The solution to the main form closing the subform in java does not close

Many coders may encounter such a problem when writing a javaGUI graphical interface: that is, there is a button on the main form. After clicking, a sub-form will pop up, and after the sub-form is closed, the main form will be closed, and We don't want to close the main form and maintain the independence of each form in resource release, which can be solved by the following code:

//this当然是指当前窗体了
this.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                this.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            }

        });

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325849381&siteId=291194637