I am using the code below to pass the information, but i would like to know other ways. In the event handler method handleSubmitButtonAction of FXMLDocumentController, i create another window loading MainFXML file. After that, i get hold of its controller and send my information to Main Window. Is there a better way to do that?
public class FXMLDocumentController implements Initializable {
@FXML
private TextField user;
@FXML
public void handleSubmitButtonAction(ActionEvent event) throws IOException {
Alert dialogo = new Alert(Alert.AlertType.INFORMATION, "User: " + user.getText() + " logged in.");
dialogo.showAndWait();
Stage stage2 = (Stage) user.getScene().getWindow();
stage2.close();
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("MainFXML.fxml"));
Parent root = (Parent) fxmlLoader.load();
MainFXMLController controller = fxmlLoader.<MainFXMLController>getController();
Scene scene = new Scene(root);
Stage stage = new Stage();
stage.setScene(scene);
stage.show();
controller.setUser(user.getText());
}