Search code examples
javaswinguser-interfaceactionlistenerwindowlistener

Creating a GUI with ActionListeners inside a method


I have a method inside one of my classes to my Java application that makes a Swing GUI and has it's own action listeners - which works fine. However, when the window is closed I need the method to return a String[] array; this is the part that is causing the problems...

I have added a simple return statement at the end of the method, but obviously Java doesn't wait for the action listeners and thinks that the method is complete once the action listeners have been added. So is there any way to "hold" a method, and then resume it when I am ready - or even, a different solution to my problem?

Thanks in Advance


Solution

  • Use a modal JDialog or a JOptionPane instead. The code that opened it will pause at that point - until the modal component is dismissed from the screen.