Question: Lab 5 has you creating a small GUI program that allows the user to enter and remove information for a series of students ( name

Lab 5 has you creating a small GUI program that allows the user to enter and remove
information for a series of students (name, year, major). Each student has their info displayed to
the right in a list. The finished version should look like this (with occasional red error text under
the ADD button):
Submit 3.java files (Student.java, StudentProfileApp.java, and StudentProfileController.java)
as well as 1 FXML file (StudentProfile.fxml) to Blackboard.
Part 1: Initial Setup & Student.java
This should be the easiest part of the assignment. First, create a JavaFX project just like in class,
and rename the default files accordingly. The main application should be StudentApp.java, the
Controller should be StudentController.java, and the scene should be StudentApp.fxml. Adjust
StudentProfileApp as needed (removing the default resolution and changing the title).
Then, create Student.java. This is a simple class that should only contain 3 fields (String name,
year, and major). Give it a non-default constructor so you can make a Student later. Lastly,
define a toString(). Remember, to successfully define toString(), you must define it to be public
String toString() exactly. It should return a String along the lines of , major.
They are a . An example of how it might look for a generic CS student could be Joe, CS
major. They are a sophomore. Without toString() defined, the list would display the Student in
raw memory form (gibberish like Student@c9fea98).
Part 2: Design the Scene
Part 2 is to design the scene to roughly match the images above. The scene mostly contains
things you should have messed with by now in the uploaded examples. There are 3 text fields
with labels next to them for the name year and major. Underneath them is a button that is used
to create a Student out of the information there. There should also be an error label underneath
the button that has red font color, used if the user tries to create a student with an empty field.
The 1 new thing is the list on the right, which is a ListView control. Just drag it in place and leave
its settings as default. Well modify its contents of it in code. That area has its own button for
deleting a selected student, as well.
Dont forget to set IDs for each control. The controller will need reference to the 3 text fields,
the error label, and the list. You also need to set the controller as well as events for clicking the
2 buttons.
Part 3: Coding the Scene Controller
First, set up some references to Controls in the scene. Youll want to have a reference to all 3
text fields as well as the error label. The last thing to add is a ListView. Creating a ListView
variable is like ArrayLists. The way I did it, for instance, was public ListView list;
Most of the code in the controller is in a createProfile(), called when the user clicks the ADD TO
LIST button. Heres an outline of the steps it should take:
1) Check if any of the 3 text fields are empty. If so, set the error label to Error: dont
leave any fields blank. and use return; to exit the method early.
2) Retrieve the values from each of the 3 text fields.
3) Create a Student object using that info.
4) Add the Student to the list of Students within the ListView. This is done via
list.getItems().add(student);
5) Clear the contents of the 3 text fields and the error label.
The last thing to add is a removeProfile() to react to the DELETE SELECTED ACCOUNT button
being clicked. It only needs 2 lines of code to retrieve and remove the selected student from the
list. First, retrieving the student in question can be done with
list.getSelectionModel().getSelectedItem(); Then, you can list.getItems().remove(theStudent).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!