Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Simulating modality on a component

843807Jun 15 2010 — edited Jun 16 2010
Hi, I am programming a naval battle game using Swing and I have run into some problems:

When I tell the user to place his ship, I need a program to wait, like a modal dialog - so thet game won't start until the ship is placed, but the gui is not frozen.

Kind of this code:
public void newGame(){
askUserAboutName(); //uses JOptionPane.showInputDialog - program freezes until user fills in the name
askUserToPlaceShips(); //cannot use JOptionPane - placing is a mouse event (click) on existing component, but need to freeze until placed
startGame();
}
So - I need to freeze the code on the second command - wait for user to place ships. Basically, it's the same like asking him about name, but placing ships dont use modal dialogs - it uses mouse listener on existing frame (the board), so when the users clicks, the ship is placed.

Hope I made myself clear.
TY for response.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 14 2010
Added on Jun 15 2010
4 comments
121 views