I've just started programming a couple of months ago for school, and I'm currently making a luggage registration system in JavaFX. My first 3 screens is where you fill in needed information into textfields. After those 3 screens the next one has to feature a summary of everything that the user has filled in in the previous 3 screens. After watching numerous tutorials on how to pass on variables between controllers, i can't get it to work.
This is my initial controller
@FXML
private void handleButtonAction1(ActionEvent event) throws IOException, Exception {
labelNumber = label_number.getText();
flightNumber = flight_number.getText();
destination = destination_.getText();
if (nullOrEmpty(labelNumber) || nullOrEmpty(flightNumber) || nullOrEmpty(destination)) {
warningLabel.setTextFill(Color.RED);
warningLabel.setText("Please fill in every field");
} else {
Stage stage = (Stage) ((Node) event.getSource()).getScene().getWindow();
//Set the second screen fxml document on stage.
SetStage setStage1 = new SetStage(stage, "FXML1Document.fxml");
//Pass variables onto FXML3document.fxml
FXMLLoader loader = new FXMLLoader(getClass().getResource("FXML3Document.fxml"));
FXML3DocumentController FXML3DocumentController = loader.getController();
FXML3DocumentController.SetTextLabelInfo(labelNumber, flightNumber, destination);
MyJDBC myJDBC = new MyJDBC("fysdatabasefinal");
String query = "INSERT INTO luggage(label_number,flight_number,destination) VALUES ('" + (labelNumber) + "','" + (flightNumber) + "','" + (destination) + "')";
myJDBC.executeUpdateQuery(query);
myJDBC.close();
}
}
On pressing a button, it's supposed to take me to the next controller(FXML1Document.fxml). It's also supposed to pass the given variables to FXML3Document.fxml
This is FXML3DocumentController
public class FXML3DocumentController implements Initializable {
@FXML
private Label first_name;
@FXML
private Label last_name;
@FXML
private Label email_address;
@FXML
private Label phone_number;
@FXML
private Label address_;
@FXML
private Label postal_code;
@FXML
private Label state_;
@FXML
private Label city_;
@FXML
private Label choice_country;
@FXML
private Label type_;
@FXML
private Label brand_;
@FXML
private Label color_;
@FXML
private Label label_number;
@FXML
private Label flight_number;
@FXML
private Label destination_;
@FXML
private Label special_char;
/**
* Initializes the controller class.
*/
@Override
public void initialize(URL url, ResourceBundle rb) {
}
@FXML
public void SetTextClientInfo(String first_name, String last_name, String email_address, String phone_number, String address_,
String postal_code, String state_, String city_, String choice_country) {
this.first_name.setText(first_name);
this.last_name.setText(last_name);
this.email_address.setText(email_address);
this.phone_number.setText(phone_number);
this.address_.setText(address_);
this.postal_code.setText(postal_code);
this.state_.setText(state_);
this.city_.setText(city_);
this.choice_country.setText(choice_country);
}
@FXML
public void SetTextLabelInfo(String label_number, String flight_number, String destination_) {
this.label_number.setText(label_number);
this.flight_number.setText(flight_number);
this.destination_.setText(destination_);
}
@FXML
public void SetTextLuggageInfo(String type_,
String brand_, String special_char) {
this.type_.setText(type_);
this.brand_.setText(brand_);
this.special_char.setText(special_char);
}
I've created 3 functions that i call in each of the 3 controllers, that get the textfield values and change the labels in the above controller.
Any help would be greatly appreciated.