简体   繁体   中英

How to make JFrame pause thread similar to how JOptionPane works

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 ?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM