62,628
社区成员
发帖
与我相关
我的任务
分享addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
if(JOptionPane.showConfirmDialog(null,"您确定要退出吗?","提示",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
});
public class Test11 extends JFrame {
public Test11(){
setTitle("hello");
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e)
{
if(JOptionPane.showConfirmDialog(null,"您确定要退出吗?","提示",
JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
{
System.exit(0);
}
}
});
setVisible(true);
}
public static void main(String[] args) {
new Test11();
}
}
完整例子符合你的要求你看一下frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);System.out.println(123);
System.exit(0);
你点击确定的时候会有123输出,你点其他的时候不会有输出