java中JFrame 窗口关闭时,弹出一个对话框提示是否确定关闭,这段代码怎么写?
能发个完整代码也行应该是这个接口吧,WindowClosing(WindowEvente)谢谢!!...
能发个完整代码也行应该是这个接口吧,WindowClosing(WindowEvent e)谢谢!!
展开
2013-12-09
展开全部
public class ButtonFrame extends JFrame {
public ButtonFrame() {
setSize(500, 500);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
if(JOptionPane.showConfirmDialog(null,"是否退出")==JOptionPane.OK_OPTION)
System.exit(0);
}
});
} public static void main(String[] args) {
new ButtonFrame().setVisible(true);
}
}
public ButtonFrame() {
setSize(500, 500);
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter(){
@Override
public void windowClosing(WindowEvent e) {
if(JOptionPane.showConfirmDialog(null,"是否退出")==JOptionPane.OK_OPTION)
System.exit(0);
}
});
} public static void main(String[] args) {
new ButtonFrame().setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询