JavaFX how to change stage

后端 未结 4 1221
不知归路
不知归路 2021-01-31 11:51

I\'m using Netbeans 7.2 with Scene Builder 1.0 to develop a JavaFX application. I have my main screen set up, and I want to have it so I click a button and it\'ll close the main

4条回答
  •  余生分开走
    2021-01-31 12:29

    I'm probably saying something similar here, but this is how I do it:

    (In this example, I am transitioning from Login.fxml to Home.fxml).

    Inside the LoginController.fxml class, I have created the following method:

    @FXML
    private void login(javafx.event.ActionEvent event) throws IOException
    {
        if(pwf1.getText().equals("dolphin"))
        {
                Parent blah = FXMLLoader.load(getClass().getResource("Home.fxml"));
                Scene scene = new Scene(blah);
                Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
                appStage.setScene(scene);
                appStage.show();
        }
        else
        {
                label1.setText("Password is incorrect. Please Try Again");
        }
    }
    

    And that's it.;)

提交回复
热议问题