buttons added to java's homework5 and makefile now works as well

This commit is contained in:
shockrahwow 2019-03-16 11:02:20 -07:00
parent 1fac09b579
commit eb82ea7ee2
5 changed files with 104 additions and 19 deletions

View File

@ -6,8 +6,49 @@ Description: Builds a basic school data tracker
Course information is also available
Input is read from file
*/
public class App {
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
import javafx.scene.layout.GridPane;
public class App extends Application {
static public School school_;
@Override
public void start(Stage stage) {
// make the initial menu with three buttons
stage.setTitle("School App");
// main menu buttons
Button instButton = new Button("Instructors");
Button studButton = new Button("Students");
Button courButton = new Button("Courses");
// creating the initial scene to draw thigns onto
GridPane grid = new GridPane();
grid.add(instButton, 1, 0, 1, 1);
grid.add(studButton, 1, 1, 1, 1);
grid.add(courButton, 1, 2, 1, 1);
Scene scene = new Scene(grid, 1280, 720);
stage.setScene(scene);
// render the scene
stage.show();
}
public static void main(String[] args) {
// First we'll create a school
School.createSchool("CSUMB");
school_ = School.getSchool();
// Next we'll populate it with some data
school_.readData("data1.txt");
school_.readData("data2.txt");
// Next we'll create the UI
launch();
}
public static void legacy_main(String[] args) {
String dataFile1 = "data1.txt";
String dataFile2 = "data2.txt";
@ -17,7 +58,9 @@ public class App {
// first we'll read in some data
System.out.println("===== Read Data 1 =====");
School SCD = new School("CSUMB");
School.createSchool("CSUMB");
School SCD = School.getSchool();
// get all basic info about the SCD
SCD.readData(dataFile1);

View File

@ -3,21 +3,46 @@ import java.util.HashMap;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
// NOTE: there will probably only be one instance of a school object ever
/* NOTE::editor: micro complains about all javafx things just ignore */
public class School {
private ArrayList<Instructor> instructorList;
private ArrayList<Course> courseList;
private ArrayList<Student> studentList;
private ObservableList<Instructor> instructorList;
private ObservableList<Course> courseList;
private ObservableList<Student> studentList;
private String name;
private static School inst = null;
public School(/*String file,*/ String schoolName) {
this.instructorList = new ArrayList<Instructor>();
this.courseList = new ArrayList<Course>();
this.studentList = new ArrayList<Student>();
private School(/*String file,*/ String schoolName) {
instructorList = FXCollections.observableArrayList();
courseList = FXCollections.observableArrayList();
studentList = FXCollections.observableArrayList();
this.name = schoolName;
//readData(file);
}
// These two methods secure the singleton pattern for ur
public static School getSchool() {
return inst;
}
public static void createSchool(String schoolName) {
if(inst == null) {
inst = new School(schoolName);
}
}
public void editCourse(Course c) {
/* Helper func to notify an actual change for the ui */
int k = courseList.indexOf(c);
courseList.set(k,c);
}
public void editStudent(Student s) {
int k = studentList.indexOf(s);
studentList.set(k,s);
}
public void readData(String filename) {
try {
@ -237,6 +262,7 @@ public class School {
}
tmp.graduate();
editStudent(tmp);
return true;
}
@ -252,22 +278,26 @@ public class School {
}
// if the student is there but not enrolled in that course then just create a new student with new data
tmp.enroll(courseID, floatGrade, letterGrade);
editStudent(tmp);
return true;
}
public void drop(int studentID, int courseID) {
for(Student s : studentList) {
if(s.id == studentID) {
s.grades.remove(courseID);
editStudent(s);
}
}
}
public void assign(int instructorID, int courseID) {
Course c = getCourse(courseID);
c.instructorID = instructorID;
c.instructorID = instructorID;
editCourse(c);
}
public void unassign(int instructorID, int courseID) {
Course c = getCourse(courseID);
c.instructorID = 0;
editCourse(c);
}
// basic printout of school infor
public void schoolInfo() {

View File

@ -1,8 +1,18 @@
all:
javac App.java Course.java Instructor.java School.java Student.java
cc=~/Downloads/jdk-11.0.2/bin/javac
fxlib=--module-path /home/shockrah/Downloads/javafx-sdk-11.0.2/lib
ctrl=--add-modules javafx.controls
env=~/Downloads/jdk-11.0.2/bin/java
run: all
@java App
jfiles=App.java Course.java Instructor.java School.java Student.java
cfiles=App
all: $(jfiles)
$(cc) $(fxlib) $(jfiles) $(ctrl)
run: $(cfile)
$(env) $(fxlib) $(ctrl) $(cfiles)
.PHONY: clean
clean:
rm -f *class

View File

@ -9,9 +9,9 @@ cfiles=HelloFX
all: $(jfiles)
$(cc) $(fxlib) $(jfiles) $(ctrl)
run:
$(env) $(fxlib) $(ctrl) $(cfile) $(cfiles)
run: $(cfile)
$(env) $(fxlib) $(ctrl) $(cfiles)
.PHONY: clean
clean:

2
338/tmp/tmp Normal file
View File

@ -0,0 +1,2 @@
~/Downloads/jdk-11.0.2/bin/java --module-path /home/shockrah/Downloads/javafx-sdk-11.0.2/lib --add-modules javafx.controls
makefile:13: recipe for target 'run' failed