我正在使用windowClosing
来在关闭特定的JFrame之前进行确认。
在关闭之前,我会得到一个确认对话框,但问题是即使我点击“否”按钮,它也会关闭。请问有什么帮助吗?
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.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
? - Hovercraft Full Of Eelsnull
作为第一个参数传递。传递对话框的父窗体,否则您的选项对话框可能会在窗体后面。原始代码是:JOptionPane.showOptionDialog(null,"Are you sure you want to exit?","Online Examination System",JOptionPane.DEFAULT_OPTION,JOptionPane.WARNING_MESSAGE,null,ObjButtons,ObjButtons[1]);
- Guillaume Polet