Issue
Flight myFlight = new Flight();
Label passL = new Label();
Label nameL = new Label();
Label ageL = new Label();
TextField passTF = new TextField();
TextField nameTF = new TextField();
TextField ageTF = new TextField();
Button addB = new Button("Add Passenger");
GridPane pane = new GridPane():
primaryStage.setTitle("");
pane.addColumn(0, passL, nameL, ageL, addB);
pane.addColumn(1, passTF, nameTF, ageTF);
Scene scene = new Scene(pane);
primaryStage.setScene(scene);
primaryStage.show();
How can I add data from TextField to object(myFlight) by pressing the Add button?
Solution
You have to set an action handling to the button. There you can extract the texts
addB.setOnAction(e -> {
String tfText = passTF.getText();
myFlight.setTf(tfText);
});
Answered By - Stefan Warminski
Answer Checked By - Marilyn (JavaFixing Volunteer)