Hey,

I need to show a 'level select' window in my game, and it's only purpose is to select a level from a list of available levels, and return the filename of that level.

In .NET, I would have made a dialog form, display it with ShowDialog such that the calling code would halt until the form returned, and then used a property to communicate which level was selected. For example, in C# this could look like
csharp Code:
  1. string levelPath = String.Empty;
  2. frmLevelSelect f = new frmLevelSelect();
  3. if (f.ShowDialog() == DialogResult.OK)
  4. {
  5.     levelPath = f.SelectedLevel;
  6. }
  7.  
  8. if (levelPath != String.Empty)
  9. {
  10.     // ... load level
  11. }

The ShowDialog call waits until the DialogResult has been set in the frmLevelSelect form, so we can be sure that, if the user pressed OK, he has actually selected a level.

If I try the same in java, replacing ShowDialog with setVisible(true), then it does not block, but it returns immediately, and obviously the user has had no chance to select a level yet.



How can I do this? Or is there no built-in mechanism for this and should I use threads?