Java 关闭JFrame=>;程序崩溃

Java 关闭JFrame=>;程序崩溃,java,swing,jframe,Java,Swing,Jframe,我有两个JFrames: ApplicationsJFrame,它是我的主要应用程序,并且 插入应用程序表单 我正在通过单击我的ApplicationsJFrame中的按钮来设置可见的InsertApplicationsForm 每次我关闭InsertApplicationsForm时,ApplicationsJFrame也会关闭,但程序仍在运行,当我最小化InsertApplicationsForm时也是如此,ApplicationsJFrame会最小化,但不会再最大化 应用程序JFram

我有两个
JFrame
s:

  • ApplicationsJFrame
    ,它是我的主要应用程序,并且
  • 插入应用程序表单
我正在通过单击我的
ApplicationsJFrame
中的
按钮
来设置可见的
InsertApplicationsForm

每次我关闭
InsertApplicationsForm
时,
ApplicationsJFrame
也会关闭,但程序仍在运行,当我最小化
InsertApplicationsForm
时也是如此,
ApplicationsJFrame
会最小化,但不会再最大化

应用程序JFrame:

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("T-AMS");
setFocusableWindowState(false);
插入应用程序表单:

public class InsertApplicationForm extends javax.swing.JFrame {

    /**
     * Creates new form InsertApplicationForm
     */
    public InsertApplicationForm() {
        initComponents();
    }
[……]

打开插入应用程序窗体:

new InsertApplicationForm().setVisible(true);

您应该将EXIT_ON_CLOSE常量int添加到主JFrame中。 相反,将WindowListener添加到临时帧:

//Suppose you have a custom Frame in your Form class
class InsertApplicationsForm extends JFrame{
//Some stuff
//...

public InsertApplicationsForm(){
//Implement
    //DO NOT ADD setDefaultCloseOperation
setVisible(true);
}

addWindowListener(new WindowAdapter(){

     @Override
    public void windowClosing(WindowEvent e){
        InsertApplicationsForm.this.dispose();
    }

});
}

所以在你的主类,或者方法,事件中,不管你怎么称呼它:

new InsertApplicationsForm();

并将自动打开一个新的JFrame,您可以关闭它,而不会影响主框架或其他框架。您甚至可以引用多个此类框架,关闭不会影响其他框架。

如何创建
InsertApplicationsForm
?是否将主框架指定为父框架?还要检查是否有任何
WindowListener
windowstatestener
。见编辑它。创建表单后,我只添加了一些文本字段和标签,这很奇怪。如果不将主框架作为父框架传递到
InsertApplicationForm
,则这两个框架应完全独立;最小化一个不应影响另一个。哪个操作系统?你有没有检查过任何窗口侦听器?刚刚和一个朋友说我不明白,因为框架应该是独立的…-操作系统是Windows 7,它有一个侦听器,可以在另一个帧中设置一个变量,这样我就可以检查该帧是否已打开。。。。。在我的其他程序中也做了同样的事情,从来都不是一个问题仍然不起作用,我想我只需要重写程序-谢谢你的帮助!我写了很多不同形式的程序。。。以前从未遇到过这样的问题。。。
new InsertApplicationsForm();