【发布时间】:2017-10-12 22:02:01
【问题描述】:
在我的应用程序中,有一个主窗口和一个用于某些更改的辅助窗口。当用户想要关闭应用程序(= 主窗口)时,我想询问用户是否确认关闭更改的辅助窗口以避免丢失更改。
这段代码在我的主课上。
我的问题是我无法从我的主课中检查辅助窗口是否打开。
注意:正在我的主控制器类上创建辅助窗口。
谢谢!
public class Main extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Main.fxml"));
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
primaryStage.getIcons().add(new Image("image.png"));
primaryStage.setTitle("Κάβα ποτών");
primaryStage.setScene(scene);
primaryStage.show();
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
@Override
public void handle(WindowEvent event) {
event.consume();
closing();
}
});
}
public void closing() {
//if(the secondary window is closed)
//Platform.exit();
//else
//ask confirmation with confirm alert
}
public static void main(String[] args) {
launch(args);
}
}
【问题讨论】:
-
欢迎来到 Stack Overflow!考虑通过单击旁边的复选标记来接受下面的答案。这将帮助@HungryCosmos 给他们更多的代表和未来的用户搜索类似的问题,让他们知道这个有一个可接受的答案。
标签: java javafx confirmation