javaswingwindowframeswingx

how to open a new window and close the current window when I click the button on java GUI?


    if (arg0.getSource() == logOut) {       //Coding Part of log out button
        JOptionPane.showMessageDialog(this, "Logout Successful");
        new MainMenus().setVisible(false);
        LoginMenu.loginmn();

    }

this is part of my java code

so in this part, I want to make a code that when the user clicks on the "logOut" button the program will open a new window and close the last window.


Solution

  • JOptionPane.showMessageDialog(this, "Logout Successful");
    

    Assuming "this" refers to the current frame then you need to add:

    this.dispose();