读书人

Swing的JFrame窗体跳转及关闭有关问题

发布时间: 2012-12-15 15:16:03 作者: rapoo

Swing的JFrame窗体跳转及关闭问题
我通过窗体A 调用 窗体 B,点击窗体B右上角的x关闭窗体B,然后就退出整个程序了
请问怎么才能关闭B,但是保留A呢
A是用SwingUtilities.invokeLater执行的
A的调用代码:

ChatView.main(null);

B:
public static void main(String[] args) throws InvocationTargetException, InterruptedException{
SwingUtilities.invokeLater(new Runnable(){
public void run() {
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try {
//设置皮肤
UIManager.setLookAndFeel( new SubstanceOfficeBlue2007LookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

ChatView cv = new ChatView();
name = "大肚腩";
cv.setTitle(name);
cv.setSize(500,400);

//cv.setResizable(false); //不允许用户改变窗口大小
cv.setDefaultCloseOperation(EXIT_ON_CLOSE);
// com.sun.awt.AWTUtilities.setWindowOpacity(cv, .7f);
cv.setVisible(true);
cv.setLocationRelativeTo(null);
}
});
}

[最优解释]
不要使用 setDefaultCloseOperation(EXIT_ON_CLOSE),使用 DISPOSE_ON_CLOSE
[其他解释]
谢谢,解决了

读书人网 >J2SE开发

热点推荐