当前位置: 技术问答>java相关
提示后为什么按YES、NO或CANCEL窗口都会退出?
来源: 互联网 发布时间:2015-05-07
本文导语: boolean GiveUp() { int temp=JOptionPane.showConfirmDialog(this,"Save Change?","Text Edit",JOptionPane.YES_NO_CANCEL_OPTION ); switch(temp) { case JOptionPane.YES_OPTION : return false; case JOptionPane.NO_OPTION : ...
boolean GiveUp() {
int temp=JOptionPane.showConfirmDialog(this,"Save Change?","Text
Edit",JOptionPane.YES_NO_CANCEL_OPTION );
switch(temp) {
case JOptionPane.YES_OPTION :
return false;
case JOptionPane.NO_OPTION :
return true;
case JOptionPane.CANCEL_OPTION :
default:
return false;
}
}
当按关闭窗口按钮后进行判断:
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
if(GiveUp()) {
System.exit(0);
System.out.print("exit");
}
}
}
int temp=JOptionPane.showConfirmDialog(this,"Save Change?","Text
Edit",JOptionPane.YES_NO_CANCEL_OPTION );
switch(temp) {
case JOptionPane.YES_OPTION :
return false;
case JOptionPane.NO_OPTION :
return true;
case JOptionPane.CANCEL_OPTION :
default:
return false;
}
}
当按关闭窗口按钮后进行判断:
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
if(GiveUp()) {
System.exit(0);
System.out.print("exit");
}
}
}
|
呵呵~我想你把这一句去掉可能就好了:super.processWindowEvent(e);