212 lines
6.8 KiB
Java
212 lines
6.8 KiB
Java
/*
|
||
Author: Alejandro Santillana
|
||
Description: Builds a basic school data tracker
|
||
keeps track of students and what course they are enrolled in as well as what courses
|
||
are offered by the school.
|
||
Course information is also available
|
||
Input is read from file
|
||
*/
|
||
import javafx.application.Application;
|
||
import javafx.scene.Scene;
|
||
import javafx.scene.control.Label;
|
||
import javafx.scene.control.TextField;
|
||
import javafx.scene.control.Button;
|
||
import javafx.scene.layout.StackPane;
|
||
import javafx.stage.Stage;
|
||
import javafx.scene.layout.GridPane;
|
||
import javafx.scene.control.ListView;
|
||
|
||
public class App extends Application {
|
||
static public School school_;
|
||
|
||
// next 3 methods are just here to populate the scene with items insede them
|
||
public Scene setStudentScene(Stage stage, Scene _prevScene) {
|
||
GridPane _layout = new GridPane();
|
||
// make the buttons
|
||
Button addButton = new Button("Add student");
|
||
Button returnButton = new Button("Return");
|
||
// adding buttons to the scene's layout
|
||
_layout.add(addButton, 1,0,1,1);
|
||
_layout.add(returnButton, 1,1,1,1);
|
||
|
||
// add event listeners for the buttons
|
||
returnButton.setOnAction(e-> stage.setScene(_prevScene));
|
||
addButton.setOnAction(e->stage.setScene(Input.studentInputScene));
|
||
|
||
// add a responsive view to the for the student list
|
||
ListView<Student> dataView = new ListView<Student>(school_.uiGetStudents());
|
||
_layout.add(dataView, 1,3,1,1);
|
||
|
||
// finally return a new scene with the finished layout
|
||
Scene ret = new Scene(_layout, 1280, 720);
|
||
return ret;
|
||
}
|
||
public Scene setInstructorScene(Stage stage, Scene _prevScene) {
|
||
GridPane _layout = new GridPane();
|
||
// buttons for this page
|
||
Button addButton = new Button("Add instructor");
|
||
Button setButton = new Button("Assign to course");
|
||
Button returnButton = new Button("Return");
|
||
|
||
// setup buttons
|
||
_layout.add(addButton, 1,0,1,1);
|
||
_layout.add(setButton, 1,1,1,1);
|
||
_layout.add(returnButton, 1,2,1,1);
|
||
|
||
// add responsive view of instructor list
|
||
ListView<Instructor> dataView = new ListView<Instructor>(school_.uiGetInstructors());
|
||
_layout.add(dataView, 1,3,1,1);
|
||
|
||
returnButton.setOnAction(e -> stage.setScene(_prevScene));
|
||
addButton.setOnAction(e -> stage.setScene(Input.instructorInputScene));
|
||
|
||
Scene ret = new Scene(_layout, 1280, 720);
|
||
return ret;
|
||
}
|
||
public Scene setCourseScene(Stage stage, Scene _prevScene) {
|
||
GridPane _layout = new GridPane();
|
||
|
||
Button addButton = new Button("Add course");
|
||
Button deleteButton = new Button("Delete course");
|
||
TextField courseField = new TextField();
|
||
Button returnButton = new Button("Return");
|
||
|
||
_layout.add(addButton, 1,0,1,1);
|
||
_layout.add(deleteButton, 1,1,1,1);
|
||
_layout.add(courseField, 2,1,1,1);
|
||
_layout.add(returnButton, 1,2,1,1);
|
||
|
||
addButton.setOnAction(e -> stage.setScene(Input.courseInputScene));
|
||
deleteButton.setOnAction(e -> Input.courseDeletion(courseField.getText()));
|
||
returnButton.setOnAction(e -> stage.setScene(_prevScene));
|
||
|
||
// add response data view for course list
|
||
ListView<Course> dataView = new ListView<Course>(school_.uiGetCourses());
|
||
_layout.add(dataView, 1,3,1,1);
|
||
|
||
Scene ret = new Scene(_layout, 1280, 720);
|
||
return ret;
|
||
}
|
||
@Override
|
||
public void start(Stage stage) {
|
||
// make the initial menu with three buttons
|
||
stage.setTitle("School App");
|
||
|
||
// Main menu comes first
|
||
GridPane grid = new GridPane();
|
||
Button instButton = new Button("Instructors");
|
||
Button studButton = new Button("Students");
|
||
Button courseButton = new Button("Courses");
|
||
// add those buttons to the main_menu scene
|
||
grid.add(instButton, 1, 0, 1, 1);
|
||
grid.add(studButton, 1, 1, 1, 1);
|
||
grid.add(courseButton, 1, 2, 1, 1);
|
||
|
||
Scene main_menu = new Scene(grid, 1280, 720);
|
||
|
||
// next we can create the other menu's
|
||
Scene studMenu = setStudentScene(stage, main_menu);
|
||
Scene instMenu = setInstructorScene(stage, main_menu);
|
||
Scene courMenu = setCourseScene(stage, main_menu);
|
||
|
||
// setup form pages
|
||
Input.initStudentInput(studMenu, stage);
|
||
Input.initInstructorInput(instMenu, stage);
|
||
Input.initCourseInput(courMenu, stage);
|
||
|
||
// now we can add the event listeners for our main menu as the other scenes now exist
|
||
instButton.setOnAction(e-> stage.setScene(instMenu));
|
||
studButton.setOnAction(e-> stage.setScene(studMenu));
|
||
courseButton.setOnAction(e-> stage.setScene(courMenu));
|
||
|
||
stage.setScene(main_menu);
|
||
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";
|
||
|
||
// course reference for demo purposes
|
||
Course course1;
|
||
Student student1;
|
||
|
||
// first we'll read in some data
|
||
System.out.println("===== Read Data 1 =====");
|
||
School.createSchool("CSUMB");
|
||
|
||
School SCD = School.getSchool();
|
||
// get all basic info about the SCD
|
||
SCD.readData(dataFile1);
|
||
|
||
System.out.println("\n===== School Info 1 =====");
|
||
SCD.schoolInfo();
|
||
|
||
// round 2 of adding info to the SCD
|
||
System.out.println("\n===== Read Data 2 =====");
|
||
SCD.readData(dataFile2);
|
||
|
||
System.out.println("\n===== School Info 2 =====");
|
||
SCD.schoolInfo();
|
||
|
||
// we'll now add some new instructors
|
||
SCD.addInstructor(700, "E. Tao", "tao@csumb.edu", "777-777-1234");
|
||
SCD.addCourse(300, "CST300 – ProSem", 700, "BIT110");
|
||
SCD.addCourse(231, "CST231 – Intro C++", 100, "BIT104");
|
||
|
||
// examples of bad courses to add
|
||
System.out.println("\n===== Failed Course Addition =====");
|
||
SCD.addCourse(306, "CST306 – GUI Dev", 250, "BIT120");
|
||
SCD.addCourse(499, "CST499 – iOS Dev", 150, "BIT104");
|
||
|
||
System.out.println("\n===== Detailed Course Info =====");
|
||
SCD.courseInfo(306);
|
||
|
||
// updateing a courses location
|
||
course1 = SCD.getCourse(205);
|
||
course1.updateLocation("Library 104");
|
||
|
||
// checking some courses' information
|
||
System.out.println("\n===== Detailed Course Info 2 =====");
|
||
SCD.courseInfo(205);
|
||
|
||
System.out.println("\n===== Detailed Course Info 3 =====");
|
||
SCD.courseInfo();
|
||
SCD.deleteCourse(231);
|
||
SCD.deleteCourse(336);
|
||
SCD.deleteCourse(338);
|
||
|
||
System.out.println("\n===== Detailed Course Info 4 =====");
|
||
SCD.courseInfo();
|
||
|
||
// adding a student (valid this time)
|
||
SCD.addStudent(5555, "Chris Watson", 205, 85.50f, "B");
|
||
System.out.println("\n===== Detailed Course Info 5 =====");
|
||
SCD.courseInfo(205);
|
||
student1 = SCD.getStudentInfo(7777);
|
||
|
||
// student info
|
||
System.out.println("\n===== Detailed Student Info =====");
|
||
System.out.println(student1);
|
||
|
||
System.out.println("\n===== Detailed Student Info 2 =====");
|
||
System.out.println(SCD.getStudentInfo(7777));
|
||
SCD.graduateStudent(5555);
|
||
|
||
System.out.println("\n===== Detailed Course Info 6 =====");
|
||
SCD.courseInfo(205);
|
||
SCD.graduateStudent(5555);
|
||
|
||
System.out.println("\n===== Good Job! Bye! =====");
|
||
}
|
||
}
|