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 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 java files Studentjava, StudentProfileApp.java, and StudentProfileController.java
as well as FXML file StudentProfilefxml to Blackboard.
Part : 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 fields String name,
year, and major Give it a nondefault 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@cfea
Part : Design the Scene
Part 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 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 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 text fields,
the error label, and the list. You also need to set the controller as well as events for clicking the
buttons.
Part : Coding the Scene Controller
First, set up some references to Controls in the scene. Youll want to have a reference to all
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:
Check if any of the 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.
Retrieve the values from each of the text fields.
Create a Student object using that info.
Add the Student to the list of Students within the ListView. This is done via
list.getItemsaddstudent;
Clear the contents of the 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 lines of code to retrieve and remove the selected student from the
list. First, retrieving the student in question can be done with
list.getSelectionModelgetSelectedItem; Then, you can list.getItemsremovetheStudent
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
