当前位置: 技术问答>java相关
记事本程序的退出问题?谢谢
来源: 互联网 发布时间:2015-03-09
本文导语: 记事本程序,单击右上角的X,弹出是否保存对话框,有YES.NO.CANCEL按钮,单击CANCEL,如何做到不退出程序,返回记事本界面 fr.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { if(...
记事本程序,单击右上角的X,弹出是否保存对话框,有YES.NO.CANCEL按钮,单击CANCEL,如何做到不退出程序,返回记事本界面
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if(statusFile.getText().endsWith("*")) {
int option = JOptionPane.showConfirmDialog(null,
"Save changes ?n(MUST choose Yes or No)", "File has been changed!", JOptionPane.YES_NO_CANCEL_OPTION);
switch(option) {
case JOptionPane.NO_OPTION :
System.exit(0);
break;
case JOptionPane.YES_OPTION :
if(fns == null) {
if(saveNewFile()) {
System.exit(0);
}
}
else {
if(saveFile()) {
System.exit(0);
}
}
break;
case JOptionPane.CANCEL_OPTION :
?????????????????
default:
break;
}
}
else {
System.exit(0);
}
}
});
fr.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
if(statusFile.getText().endsWith("*")) {
int option = JOptionPane.showConfirmDialog(null,
"Save changes ?n(MUST choose Yes or No)", "File has been changed!", JOptionPane.YES_NO_CANCEL_OPTION);
switch(option) {
case JOptionPane.NO_OPTION :
System.exit(0);
break;
case JOptionPane.YES_OPTION :
if(fns == null) {
if(saveNewFile()) {
System.exit(0);
}
}
else {
if(saveFile()) {
System.exit(0);
}
}
break;
case JOptionPane.CANCEL_OPTION :
?????????????????
default:
break;
}
}
else {
System.exit(0);
}
}
});
|
先加上这句话:
fr.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );
fr.setDefaultCloseOperation( WindowConstants.DO_NOTHING_ON_CLOSE );