There are 2 forms, forms have different controller classes, 1 form loads another one by pressing a button. How to send 2 form information from 1 form.

To change forms I use - there is a static Stage on which I am changing the Scene:

public static Stage primaryStage; @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("/sample/sample.fxml")); primaryStage.setScene(new Scene(root)); runStage(primaryStage); } public static void runStage(Stage stage) throws IOException { primaryStage = stage; primaryStage.show(); } public static void main(String[] args) { launch(args); } 

Change the form by clicking on the button:

  public void EditBook() throws IOException { Parent root = FXMLLoader.load(getClass().getResource("/sample/EditBook.fxml")); Main.primaryStage.setScene(new Scene(root)); Main.primaryStage.show(); } 

I would like to know how to correctly change the forms and see an example of the interaction between the forms.

    1 answer 1

    The interaction between the forms can be done through a method call on the controller.

    To get a controller, you need to write like this

     FXMLLoader loader = new FXMLLoader("/sample/EditBook.fxml"); Parent root = loader.load(); Main.primaryStage.setScene(new Scene(root)); ControllerClass controllerEditBook = loader.getController(); //получаем контроллер для второй формы controllerEditBook.someMethod(someParameters); // передаем необходимые параметры Main.primaryStage.show(); 
    • Thank you, the parameters are listed on the shelves. It turns out in any method class ControllerClass I can pass the parameters? - bsuart
    • You can call any method from ControllerClass - Andrew Bystrov