I'm currently designing a basic game as a way to experiment with different GUI components. At one point in the game I generate a new frame for which the player must select a certain option. I have ActionListeners
and everything set up so that the player can select said option. However, I also want the frame from the main game to be able to tell when an option is selected so that the option can be executed. Any tips on how to do this? I'm currently using a WindowFocusListener
to detect focus goes off of the menu and back to the main game, but that seems somewhat unreliable.
Asked
Active
Viewed 80 times
-2

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373

Dominic
- 1
- 1
-
Please add some of your attempted code and what is going wrong so we can better answer your question. – Holden Lewis Feb 24 '13 at 04:51
1 Answers
4
I generate a new frame..
Use a modal JDialog
or a JOptionPane
instead. Given the 'modal nature, the code will 'stop' at the line that sets the component visible, and wait for it to be closed before proceeding to the next line.

Community
- 1
- 1

Andrew Thompson
- 168,117
- 40
- 217
- 433
-
@HovercraftFullOfEels I might have flagged this as a duplicate, but I suspect that this is a hard topic to search. Not that that is a good excuse.. – Andrew Thompson Feb 24 '13 at 04:54
-
[This question](http://stackoverflow.com/questions/6077889/how-to-make-the-main-gui-thread-wait-until-a-separate-pop-up-window-is-disappe?rq=1) may be considered one possible duplicate. – Hovercraft Full Of Eels Feb 24 '13 at 04:56
-
@HovercraftFullOfEels Yep. Been there, seen that, entered the up-vote. :) I suspect this question will be closed *very* soon.. – Andrew Thompson Feb 24 '13 at 04:59