What happens after the execution of actionPerformed
? Is there any way I can go back to the main class of the program after actionPerformed
executes?
Here is the sample of the code:
public final class JavaGame extends JFrame {
public JavaGame(){
int x = cache();
JButton butt = new JButton("NEW");
newG gameX = new newG();
butt.addActionListener(gameX);
}
public class gameFunction implements ActionListener{
@Override
public void actionPerformed(ActionEvent e){
if(e.getSource() == butt){
//do something logic here. Like go to another stage of the game
JOptionPane.showMessageDialog(null, Success!");
}
}
}
public cache(){
return 1;
}
public static void main(String[] args) {
new JavaGame();
}
}
After actionPerformed
runs, what happens next?
In my real code, after actionPerformed
runs, the stage of my game is still the same. How can I go back to main
so that I can start a new stage without closing and opening the program again?