There are a lot questions on this, but they weren't able to help me or I didn't understand it..
Basically I want user to press the button before system goes back to main method. In this case if system goes back to main method, system will quit.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test123 implements ActionListener{
JTable table;
JButton button;
JFrame frame;
public test123 (){
frame = new JFrame();
frame.setLayout(null);
button = new JButton("Finish");
button.setBounds(200, 10, 70, 40);
button.addActionListener(this);
frame.add(button);
frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.setSize(600, 200);
frame.setVisible(true);
frame.setTitle("TEst123");
}
public void actionPerformed(ActionEvent e){
if(e.getSource() == button){
System.out.println("message....");
}
}
public static void main(String arg[]){
test123 gui = new test123();
System.exit(0);
}
}
Sorry if it was just me lacking the understanding and thank you for help.
EDIT: Maybe I explained this incorrectly or displayed it incorrectly. Lets say if the system goes back to main system it will do something I don't want, therefor I want the user to press the button to go back to the main system or do "the thing". Sorry for bad explanation, including this one.
This class is separate from my work and I just used it to test stuff... In my project, user can choose from several buttons (lets say main method is the menu in this case). The user presses a button goes to a new window/frame, if the program doesn't pause or waits for button to be pressed, it will go back to main method.