close the JFrame using a button on jinternalframe

45 Views Asked by At

I am new to Java language.In my project i created a JInternalFrame inside a JDesktopPane that include in the JFrame(A). In that JInternalFrame i created a button that open another JFrame(B). So what i want is when I am clicking the button the Previous JFrame(A) must dispose.

I tried to create an object of JFrame(A) and use dispose method. But it's not working.

This is the code in JFrame(A)

private void panelProfileMouseClicked(java.awt.event.MouseEvent evt) {                                          
        DBConnection connection = new DBConnection();
        connection.getData(username);
        Profile profile = new Profile(connection.firstname,connection.lastname,connection.gender,connection.password); //Calling JInternalFrame
        smallDesktop.removeAll();
        smallDesktop.add(profile).setVisible(true);
    }

This is the code in JInternalFrame that calls other JFrame(B)

private void btnChangePasswordActionPerformed(java.awt.event.ActionEvent evt) {                                                  
        new ChangePassword().setVisible(true);
        
    } 
2

There are 2 best solutions below

0
CODERZ On

As the comment you got earlier, it is surely true that you didn't clarify it properly. But I think what you can do is to use System.Exit(0); instead of dispose

2
n00bcod3z On
private void panelProfileMouseClicked(java.awt.event.MouseEvent evt) {

DBConnection connection = new DBConnection();
connection.getData(username);
Profile profile = new Profile(connection.firstname, connection.lastname, connection.gender, connection.password);

profile.setMainFrame(this);

smallDesktop.removeAll();
smallDesktop.add(profile).setVisible(true); }