两个JFrame,
JFrame Main; // Main JFrame
JFrame Sub; //Second JFrame that is initialized from within Main via a JMenuItems ActionListener.
mainMenuItem.setActionListener(new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
try{
Sub subFrame = new Sub();
subFrame.setVisible(true);
}catch(Exception e){}
}
});
}
Run Code Online (Sandbox Code Playgroud)
问题是每当我关闭第二个JFrame(Sub)时它会关闭第一个JFrame(Sub).
两者JFrame都有:
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Run Code Online (Sandbox Code Playgroud)
这是问题的一部分吗?
EXIT_ON_CLOSE表示System.exit()在帧关闭时立即退出程序().
您可能希望将其设置为DISPOSE_ON_CLOSE,然后WindowListener仅在两个帧都已关闭时添加并关闭程序.
(或者,也许你只想要主框架EXIT_ON_CLOSE)
| 归档时间: |
|
| 查看次数: |
183 次 |
| 最近记录: |