I have this test code and I want the method to return a value when the button is pressed. What would be the best way to go about that?
public String test(){
JFrame frame=new JFrame();
frame.setSize(800,600);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
JButton button=new JButton("Click Me!");
frame.add(button);
}
I have tried adding an ActionListener
, but I see no way of returning a value from the parent method.
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//A return here would not work
}
});