From eb82ea7ee2c3bedd21a81abad236ca220fbcce93 Mon Sep 17 00:00:00 2001 From: shockrahwow Date: Sat, 16 Mar 2019 11:02:20 -0700 Subject: [PATCH] buttons added to java's homework5 and makefile now works as well --- 338/homework5/App.java | 47 ++++++++++++++++++++++++++++++++++-- 338/homework5/School.java | 50 +++++++++++++++++++++++++++++++-------- 338/homework5/makefile | 18 ++++++++++---- 338/tmp/makefile | 6 ++--- 338/tmp/tmp | 2 ++ 5 files changed, 104 insertions(+), 19 deletions(-) create mode 100644 338/tmp/tmp diff --git a/338/homework5/App.java b/338/homework5/App.java index d2c684c..39e2723 100644 --- a/338/homework5/App.java +++ b/338/homework5/App.java @@ -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); diff --git a/338/homework5/School.java b/338/homework5/School.java index 275b671..95e24ee 100644 --- a/338/homework5/School.java +++ b/338/homework5/School.java @@ -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 instructorList; - private ArrayList courseList; - private ArrayList studentList; + private ObservableList instructorList; + private ObservableList courseList; + private ObservableList studentList; private String name; + + private static School inst = null; - public School(/*String file,*/ String schoolName) { - this.instructorList = new ArrayList(); - this.courseList = new ArrayList(); - this.studentList = new ArrayList(); + 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() { diff --git a/338/homework5/makefile b/338/homework5/makefile index 18fa62a..23cf536 100644 --- a/338/homework5/makefile +++ b/338/homework5/makefile @@ -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 diff --git a/338/tmp/makefile b/338/tmp/makefile index 74727bb..fe88cc0 100644 --- a/338/tmp/makefile +++ b/338/tmp/makefile @@ -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: diff --git a/338/tmp/tmp b/338/tmp/tmp new file mode 100644 index 0000000..89da530 --- /dev/null +++ b/338/tmp/tmp @@ -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