按YES之前确认退出Java程序 [英] confirmation before press YES to exit program in Java
本文介绍了按YES之前确认退出Java程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void windowClosing(java.awt.event.WindowEvent evt)
{
int confirmed = JOptionPane.showConfirmDialog(null, "Exit Program?","EXIT",JOptionPane.YES_NO_OPTION);
if(confirmed == JOptionPane.YES_OPTION)
{
dispose();
}
}
我想按关闭窗口按钮关闭程序确认...但是当我选择否回到我的Jframe时,它仍然可以帮助我退出程序???
I want to close program by pressing Close Window Button with confirmation...But when I choose "No" to back to my Jframe, it still helps me to exit the program???
推荐答案
根据我的理解你想要这样的东西
From what i understand you want something like this
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
int confirmed = JOptionPane.showConfirmDialog(null,
"Are you sure you want to exit the program?", "Exit Program Message Box",
JOptionPane.YES_NO_OPTION);
if (confirmed == JOptionPane.YES_OPTION) {
dispose();
}
}
});
如果你想在某个按钮上使用它,请按下类似的功能。把听众放在上面并做同样的事情。但我不确定我的问题是否正确。但是如果你想使用按钮使用 ActionListener 和动作执行方法。
If you want to use it on some button do similiar function to button. Put listener on it and do same. But I'm not sure if I get your question right. But If you want to use button use ActionListener and action performed method.
检查问题 - Java - 关闭JFrame窗口时的消息
这篇关于按YES之前确认退出Java程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文