在按 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 和 action executed 方法.
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屋!
查看全文