Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 456
Andy Avatar asked Jan 19 '23 19:01

Andy


1 Answers

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.

like image 154
Andrew Thompson Avatar answered Jan 30 '23 10:01

Andrew Thompson