【发布时间】:2015-04-16 20:59:04
【问题描述】:
我有一个 JFrame,如果我按下右上角的关闭按钮,我会调用一个 JDialog 并询问用户是否真的想要关闭。
这是我的主 JFrame 中关闭按钮上的 ActionListener:
... //关闭监听器 addWindowListener(new WindowAdapter() {//如果 Alt+F4 调用“wirklich schließ3n”窗口 @覆盖 公共无效窗口关闭(窗口事件事件){ MainGuiWindow.this.saveSettings(); CloseDialog cd = new CloseDialog(MainGuiWindow.this);
if (cd.getResult()) {
System.exit(0);
} else {
//MainGuiWondow is "setVisible(false)" but still running | I don't know how to fix it
MainGuiWindow.this.setVisible(true);//doesn't work
}
}
});
JDialog 只有两个按钮(是/否)(按下任何按钮后我调用 dispose(); 在 JDialog 中按钮的 ActionListeners 中和 dispose(); 我返回答案: 是返回真 没有返回false
谁能告诉我在我的 MainGuiWindow 中关闭 ActionListener 的 else 情况下该怎么做。 CloseDialog 是 dispose() 的关闭原因;但主窗口是 setVisible(false);但仍在运行
【问题讨论】:
-
你到底想在 else 块中做什么??
-
尝试使用
frame.setDefaultOperationOnClose(WindowConstants.x)-- 如果您要关闭,请使用 EXIT_ON_CLOSE 表示 x,如果没有,请使用 DO_NOTHING_ON_CLOSE。
标签: java swing jframe oncloselistener