/home/caleb/ASDV-Java/Semester 3/Assignments/lab2_FX2_F22_part1/src/lab2_fx2_f22_part1/ShowGridPane2.java |
nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt
nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java
package lab2_fx2_f22_part1;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
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 ShowGridPane2 extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
pane.setPadding(new Insets(11.5, 12.5, 13.5, 14.5));
pane.setHgap(5.5);
pane.setVgap(5.5);
pane.add(new Label("First Name:"), 0, 0);
TextField fName = new TextField();
pane.add(fName, 1, 0);
pane.add(new Label("MI:"), 0, 1);
TextField mInit = new TextField();
pane.add(mInit, 1, 1);
pane.add(new Label("Last Name:"), 0, 2);
TextField lName = new TextField();
pane.add(lName, 1, 2);
pane.add(new Label("Gender, M/F/nb:"), 0, 3);
TextField gender = new TextField();
gender.setMaxSize(40, 20);
pane.add(gender, 1, 3);
Button button = new Button("Add Person");
EventHandler eventHnadler = new EventHandler<ActionEvent>(){
@Override
public void handle(ActionEvent t)
{
System.out.println("Added person:");
System.out.println(fName.getText() + " " + mInit.getText() + " " + lName.getText());
System.out.println("Gender: " + gender.getText());
}
};
button.setOnAction(eventHnadler);
pane.add(button, 0, 4);
GridPane.setHalignment(button, HPos.LEFT);
Scene scene = new Scene(pane);
primaryStage.setTitle("ShowGridPane");
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}