我在做Swing程序时,程序启动时有一个主窗口,还有其他几个窗口,当我点击主窗口右上角的叉号时,弹出确认窗口,当用户点击“确认“时,便结束程序,当点击“否“时,主窗口不关闭,我的代码如下:
void exitApplication()
{
try {
// Beep
Toolkit.getDefaultToolkit().beep();
// Show a confirmation dialog
int reply = JOptionPane.showConfirmDialog(this,
"确认删除吗?",
"消息" ,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
// If the confirmation was affirmative, handle exiting.
if (reply == JOptionPane.YES_OPTION)
{
this.setVisible(false); // hide the Frame
for(int i=0;i<count;i++)
thread[i].stop();
log.stop();
getStatus.stop();
this.dispose(); // free the system resources
System.exit(0); // close the application
}
}
现在的问题时,当我点击“否“时,主窗口关闭,但程序仍然在运行,我不想让用户点击“否“时主窗口关闭,恳求高手指教,在线等.......
void exitApplication()
{
try {
// Beep
Toolkit.getDefaultToolkit().beep();
// Show a confirmation dialog
int reply = JOptionPane.showConfirmDialog(this,
"确认删除吗?",
"消息" ,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
// If the confirmation was affirmative, handle exiting.
if (reply == JOptionPane.YES_OPTION)
{
this.setVisible(false); // hide the Frame
for(int i=0;i<count;i++)
thread[i].stop();
log.stop();
getStatus.stop();
this.dispose(); // free the system resources
System.exit(0); // close the application
}
}
现在的问题时,当我点击“否“时,主窗口关闭,但程序仍然在运行,我不想让用户点击“否“时主窗口关闭,恳求高手指教,在线等.......
JFrame.setDefaultColseOperation(JFrame.DO_NOTHING_ON_CLOSE);可能有拼写错误
JFrame.setDefaultColseOperation(JFrame.DO_NOTHING_ON_CLOSE);