第1楼 2007-07-23 05:21 oosi 写道:
关于WindowAdapter之Closing的问题
下面这段程序运行时,点击关闭按钮时弹出对话框,但在弹出对话框的时却关闭了主窗口。
但我想让在弹出对话框时不关闭主窗口,请问应该怎样修改呢?
谢谢!!!
import javax.swing.*;
import java.awt.event.*;
public class Sy extends JFrame {
Sy(){
addWindowListener(new QuitWindow());
setVisible(true);
setSize(300,200);
}
class DDialog extends JDialog {
DDialog(){
setSize(200,100);
setVisible(true);
}
}
class QuitWindow extends WindowAdapter{
public void windowClosing(WindowEvent e){
new DDialog();
}
}
public static void main(String[] args){
new Sy();
}
}
第3楼 2007-07-31 12:14 daifei4321 写道:
回复: 关于WindowAdapter之Closing的问题
是JFrame吧,那么设置JFrame的方法:
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
那个关闭按钮就不直接起作用了.
然后就象你写的那样了.