1个回答
2013-07-11
展开全部
给你一个演示程序吧 import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Test { public static void main(String args[]) {
final JFrame f = new JFrame("捕获关闭事件");
f.setSize(200, 200);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
int result = JOptionPane.showConfirmDialog(f,"确实要关闭程序吗?","警告",JOptionPane.OK_CANCEL_OPTION);
if(result==JOptionPane.OK_OPTION)
System.exit(0);
}
});
f.setVisible(true);
}
}
import javax.swing.JOptionPane;
public class Test { public static void main(String args[]) {
final JFrame f = new JFrame("捕获关闭事件");
f.setSize(200, 200);
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
int result = JOptionPane.showConfirmDialog(f,"确实要关闭程序吗?","警告",JOptionPane.OK_CANCEL_OPTION);
if(result==JOptionPane.OK_OPTION)
System.exit(0);
}
});
f.setVisible(true);
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询