I am making a game and whenever the player comes in contact with an enemy, I want a JFrame
to pop up asking if you want to fight the enemy, but when the JFrame
pops up, the game keeps running in the background. I noticed with JOptionPanes
, the thread pauses until the JOptionPane
is gone. How would i get a similar effect with a JFrame
?
Asked
Active
Viewed 506 times
1

Paul Samsotha
- 205,037
- 37
- 486
- 720

Ryan Hosford
- 519
- 1
- 9
- 25
-
possible duplicate of [How to wait for a JFrame to close before continuing?](http://stackoverflow.com/questions/12335733/how-to-wait-for-a-jframe-to-close-before-continuing) – Hovercraft Full Of Eels Apr 22 '14 at 00:37
-
1*"..the game keeps running in the background. I noticed with JOptionPanes, the thread pauses until the JOptionPane is gone."* That is entirely wrong. The **user** is blocked from accessing the main UI, but any animation (if done correctly) keeps animating away. – Andrew Thompson Apr 22 '14 at 01:10
1 Answers
2
Solution: don't use a JFrame -- You're asking for a window that acts as a modal dialog -- so use a modal dialog, a JDialog to be exact. Note that this is exactly what JOptionPane does.

Hovercraft Full Of Eels
- 283,665
- 25
- 256
- 373
-
Can i still do the same thing that JFrames do? Such as card layouts, buttons, etc. – Ryan Hosford Apr 22 '14 at 00:53
-
@RyanHosford: it can do all of those things. Understand that just like a JFrame, it is a top-level window. It can't create another icon on your icon bar. And closing it cannot automatically close the application (unless you write code specifically to do this). – Hovercraft Full Of Eels Apr 22 '14 at 00:54