How can I use a variable from another Controller in JavaFX

前端 未结 1 1338
情深已故
情深已故 2020-12-03 16:24

I have two scenes Login.fxml and MainView.fxml and two diferent controllers LoginController.java and MainViewControler.java

In LoginController I do the whole process

相关标签:
1条回答
  • 2020-12-03 16:54

    Use a variation on the solution in Passing Parameters JavaFX FXML.

    Setup a LoginManager which has a reference to both the LoginController and the MainViewController.

    1. The loginManager creates a login screen using the loginController and passes a reference to itself to the loginController.
    2. When login has passed, the loginController notifies the loginManager of the login sessionID.
    3. The loginManager can then create a MainViewController, passing the mainViewController the sessionID and replacing the scene contents with the main view.

    Here is a link to some sample code to demonstrate this approach. login screen mainview screen

    0 讨论(0)
提交回复
热议问题