JavaFX-show another scence by click one button

1505 ワード

    @FXML

    private void handleButtonAction(ActionEvent event) throws Exception {

        System.out.println("You clicked me!");

        label.setText("Hello World!");



        //aslo I want to show another scence



        //1.Get application stage

        Stage currentStage = (Stage) ((Node) event.getSource()).getScene().getWindow();

        //2.Create new scence from fxml

        Parent root = FXMLLoader.load(getClass().getResource("mainUI/mianUI.fxml"));



        Scene scene1 = new Scene(root);

        //3.Set new scence to the stage

        currentStage.setScene(scene1);

        //currentStage.show();

    }