Question: Assignment: Augment the GUI from Lab 2 so you can create the appropriate object from Lab 1. Create a new project Lab3. Copy the Person/Faculty/Student
Assignment:
Augment the GUI from Lab 2 so you can create the appropriate object from Lab 1.
- Create a new project Lab3.
- Copy the Person/Faculty/Student classes from Lab1 and incorporate them in Lab 3.
- Copy/rename your Lab2 main driver into this project as Lab3.java :
- Add a label/text field for Display Name:
- Add a label/textarea for toString
- Make the Faculty/Student radio button toggle the visibility of the classification and degree GUI components accordingly. (e.g. when Student is selected, classification components should be visible and the degree components should *not* be visible)
- A submit button should show validate the contents, and if successful, should create the appropriate object from your previous lab (Student or Faculty), populate the fields with the values of the GUI and reflect the contents of the displayName() and toString() methods in separate text boxes within the GUI. While technically you could update the contents of the display name and toString boxes without actually creating a Student/Faculty, the purpose of this lab is to move towards using objects in a real-world fashion
Lab 2 GUI>>
//javaFx code
import javafx.application.Application; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.GridPane; import javafx.stage.Stage; import javax.swing.*; import java.util.ArrayList; import java.util.Arrays; public class AddPersonGUI extends Application { TextField txtId,txtFirstName,txtLastName,txtDegree1, txtDegree2,txtDegree3,txtDegree4,txtDegree5; Label lblId,lblTitle,lblFirstName,lblLastName,lblBirtDate, lblType,lblClass,lblDegrees; Button btnSubmit,btnReset; ToggleGroup btnGroup; RadioButton rdfaculty,rdStudent; DatePicker birthDatePicker; ComboBox comboBoxID,comboBoxClass; @Override public void start(Stage primaryStage) throws Exception { ObservableList options = FXCollections.observableArrayList( "Mr.", "Miss.", "Mrs.", "Dr." ,"Ms." ); GridPane gridPane= new GridPane(); //Setting size for the pane gridPane.setMinSize(400, 200); //Setting the padding gridPane.setPadding(new Insets(10, 10, 10, 10)); //Setting the vertical and horizontal gaps between the columns gridPane.setVgap(5); gridPane.setHgap(5); //Setting the Grid alignment gridPane.setAlignment(Pos.TOP_LEFT); //============= lblId = new Label("ID: "); txtId = new TextField(); gridPane.add(lblId,0,0,1,1); gridPane.add(txtId,1,0,1,1); //========================= lblTitle= new Label("Title: "); comboBoxID= new ComboBox(); comboBoxID.setItems(options); gridPane.add(lblTitle,0,1,1,1); gridPane.add(comboBoxID,1,1,1,1); //========================== lblFirstName = new Label("FirstName: "); txtFirstName= new TextField(); gridPane.add(lblFirstName,0,2,1,1); gridPane.add(txtFirstName,1,2,1,1); //========================== lblLastName = new Label("LastName: "); txtLastName= new TextField(); gridPane.add(lblLastName,0,3,1,1); gridPane.add(txtLastName,1,3,1,1); //===================================== lblBirtDate = new Label("BirthDate: "); birthDatePicker = new DatePicker(); gridPane.add(lblBirtDate,0,4,1,1); gridPane.add(birthDatePicker,1,4,1,1); //============================ btnGroup= new ToggleGroup(); lblType = new Label("Type: "); rdfaculty = new RadioButton("Faculty"); rdStudent = new RadioButton("Student"); //add to button group rdStudent.setToggleGroup(btnGroup); rdfaculty.setToggleGroup(btnGroup); gridPane.add(lblType,0,5); gridPane.add(rdfaculty,1,5,2,1); gridPane.add(rdStudent,2,5); //============================= lblClass= new Label("Class: "); comboBoxClass = new ComboBox(); gridPane.add(lblClass,0,6); gridPane.add(comboBoxClass,1,6); //===================== lblDegrees = new Label("Degrees: "); txtDegree1 = new TextField(); txtDegree2 = new TextField(); txtDegree3 = new TextField(); txtDegree4 = new TextField(); txtDegree5 = new TextField(); gridPane.add(lblDegrees,0,7); gridPane.add(txtDegree1,1,7); gridPane.add(txtDegree2,1,8); gridPane.add(txtDegree3,1,9); gridPane.add(txtDegree4,1,10); gridPane.add(txtDegree5,1,11); //======================== btnSubmit = new Button("Submit"); btnReset = new Button("Reset"); gridPane.add(btnSubmit,0,12); gridPane.add(btnReset,1,12); Scene scene = new Scene(gridPane); primaryStage.setTitle("Person Add"); primaryStage.setHeight(500); primaryStage.setWidth(350); primaryStage.setResizable(false); primaryStage.setScene(scene); primaryStage.show(); } public static void main(String[] args) { launch(args); } } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
