0

I have written some coding that has a GUI that has an enter button that, when clicked, opens the tool that I have created, but what I also want the jbutton to do is to close the first GUI down as well as open the tool I have created, I have tried changing the setVisible(true/false); statements but they just hide the GUI's and it doesnt run.

So to sum up, I want my JButton to have two functionalities, one to close the current GUI and one to open the tool I have created.

I think it has something to do with this coding to make the enterButton close the GUI:

public void actionPerformed(ActionEvent e){ 
    if(e.getSource() == enterButton){
        // coding to make the GUI exit???
    }
}
mKorbel
  • 109,107
  • 18
  • 130
  • 305
tom bannister
  • 77
  • 1
  • 10

1 Answers1

2

You can use System.exit(0) like this :

public void actionPerformed(ActionEvent e){ 
    if(e.getSource() == enterButton){

        //coding to make the GUI exit???

        System.exit(0); 
    }
}

or use dispose()

public void actionPerformed(ActionEvent e){ 
    if(e.getSource() == enterButton){
        //coding to make the GUI exit???

        this.dispose();
    }
}
Mahmoud Gamal
  • 75,299
  • 16
  • 132
  • 159
Alya'a Gamal
  • 5,554
  • 18
  • 34