This is the GUI CODES
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class PersonGUI extends Application {
// defining important variables
private TextField fname, lname, idNum, city;
private Button save, cancel;
@Override
public void start(Stage primaryStage) {
// creating a GridPane
GridPane root = new GridPane();
// setting padding
root.setPadding(new Insets(10));
// setting spacing between elements in gridpane
root.setHgap(10);
root.setVgap(10);
// adding label and text field for first name
root.add(new Label("First Name: "), 0, 0); // col 0, row 0
fname = new TextField();
root.add(fname, 1, 0); // col 1, row 0
// repeating for every other data fields
root.add(new Label("Last Name: "), 0, 1);
lname = new TextField();
root.add(lname, 1, 1);
root.add(new Label("Id Number: "), 0, 2);
idNum = new TextField();
root.add(idNum, 1, 2);
root.add(new Label("City: "), 0, 3);
city = new TextField();
root.add(city, 1, 3);
// creating the two buttons and adding them
save = new Button("Save");
cancel = new Button("Cancel");
root.add(save, 0, 4);
root.add(cancel, 1, 4);
// setting up and displaying a scene
Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setTitle("");
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
Instructions
Using the GUI you developed in the First Java FX lab, add an action handler to the Save button.
The action handler should read the information from the various TextFields in the GUI and use it to create an instance of the attached Person class. Once the object is created, print the toString to the console.