在关闭JFrame之前显示提示 [英] Show prompt before closing JFrame
本文介绍了在关闭JFrame之前显示提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在关闭特定JFrame之前使用 windowClosing
进行确认。
I am using windowClosing
to confirm before closing a particular JFrame.
关闭前我得到一个确认对话框但问题是它即使我点击否按钮也会关闭。有什么帮助吗?
Before closing I get a confirm dialog but the problem is it closes even if I click the NO button. Any help please?
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent we)
{
String ObjButtons[] = {"Yes","No"};
int PromptResult = JOptionPane.showOptionDialog(null,
"Are you sure you want to exit?", "Online Examination System",
JOptionPane.DEFAULT_OPTION, JOptionPane.WARNING_MESSAGE, null,
ObjButtons,ObjButtons[1]);
if(PromptResult==0)
{
System.exit(0);
}
}
});
推荐答案
您的JFrame默认关闭操作设置为什么?您需要确保它已设置为: jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
What is your JFrame's default close operation set to? You need to make sure that it been set to: jFrame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
这篇关于在关闭JFrame之前显示提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文