我实际上正在开发 GUI 应用程序,当我运行这个应用程序时,会出现一个登录窗口 成功登录后,我有一个按钮,我有 MDI 申请表,其中有菜单 在菜单中,当我单击菜单项时,我有菜单项 Jframe 打开到这里,我没有问题
但是当我关闭 Jframe 时,整个应用程序都会退出
登录表单代码
<小时/>public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Login().setVisible(true);
}
});
按钮代码
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
NewMDIApplication n = new NewMDIApplication();
n.show();
this.setVisible(false);
}
<小时/>
MDI应用程序表单代码
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
IVITEM i = new IVITEM();---- this is that form that opens inside the MDI appliaction
i.show();
}
<小时/>
最佳答案
在 IVITEM 类中添加此代码
this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
并在主窗口的主菜单中添加菜单项“退出” 并在其操作中使用
System.exit(0);
这将关闭所有子窗口
关于java - 在 netbeans 7.0 中的 java swing 中关闭 Jframe 时应用程序退出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5993244/