Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/381.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JavaFX如何重置应用程序?_Java_Javafx_Javafx 8 - Fatal编程技术网

JavaFX如何重置应用程序?

JavaFX如何重置应用程序?,java,javafx,javafx-8,Java,Javafx,Javafx 8,我的代码打开了另一个窗口,但第一个窗口仍然打开。如何关闭第一个窗口 ButtonType continue = new ButtonType("Continue"); ButtonType exit= new ButtonType("Exit"); alert.getButtonTypes().setAll(continue, exit); Optional<ButtonType> result = alert.show

我的代码打开了另一个窗口,但第一个窗口仍然打开。如何关闭第一个窗口

        ButtonType continue = new ButtonType("Continue");
        ButtonType exit= new ButtonType("Exit");
        alert.getButtonTypes().setAll(continue, exit);
        Optional<ButtonType> result = alert.showAndWait();
        if (result .get() == continue ) {
            Controllerxx = new commandCenter();
            centerFX newFX= new centerFX ();
            Stage stage = new Stage();
            newFX.start(stage);
        } else if (result .get() == exit) {
            Platform.exit();
        }
ButtonType continue=新的ButtonType(“continue”);
按钮类型退出=新按钮类型(“退出”);
alert.getButtonTypes().setAll(继续,退出);
可选结果=alert.showAndWait();
if(result.get()==继续){
Controllerxx=新命令中心();
centerFX newFX=新的centerFX();
阶段=新阶段();
新外汇开始(阶段);
}else if(result.get()=退出){
Platform.exit();
}

您可以尝试以下方法:

    btn.setOnAction((ActionEvent event) -> {
        ((Node) (event.getSource())).getScene().getWindow().hide();
    });
您可以通过退出按钮的
动作事件
获取当前场景,然后将其关闭。

或者干脆
btn.getScene().getWindow().hide()
,因为您知道
btn
是事件的来源。