JOptionPane inside of switch statement?

Started by
5 comments, last by stein102 11 years ago

I have an JOptionPane inside of my switch statement, but if you take more than a few seconds to enter your input, the program stops responding. Why does this happen? Is there a workaround?


				switch(selection){
				case 60:
					brickSelection = 1;
					break;
				case 61:
					brickSelection = 2;
					break;
				case 62:
					brickSelection = 3;
					break;
				case 63:
					fileName = JOptionPane.showInputDialog(null, "What would you like to call
                                        your level?","Save Level",3);
					break;
				case 64:
					sbg.enterState(GameStart.MENU);
					break;
				}

Advertisement

I think I figured out where the error is. The game is using Slick2D API and the JOptionPane stops the game loop and causes it to stop responding. Is this correct?

I think I figured out where the error is. The game is using Slick2D API and the JOptionPane stops the game loop and causes it to stop responding. Is this correct?

Yes, JOptionPane is a modal window, which will stop the code where you open the dialog. If you like to continue your game, you should consider using either a non-modal window or an other thread.

I think I figured out where the error is. The game is using Slick2D API and the JOptionPane stops the game loop and causes it to stop responding. Is this correct?

Yes, JOptionPane is a modal window, which will stop the code where you open the dialog. If you like to continue your game, you should consider using either a non-modal window or an other thread.

Would there be a way to not have it in another thread? It's just for a level editor and I don't need to have any logic updates while the user is in the JOptionPane.

It's just for a level editor and I don't need to have any logic updates while the user is in the JOptionPane.

Ok, it should be clear why the program stops processing while the dialog is open, but the question is, once you close the option pane, does the program continue or is it still not responding ?

When you use the time as input parameter for your game, a larger break might break your code. E.g. if you expect an average frame duration of 20-100ms and suddenly you got several seconds, your program could run into trouble.

It's just for a level editor and I don't need to have any logic updates while the user is in the JOptionPane.

Ok, it should be clear why the program stops processing while the dialog is open, but the question is, once you close the option pane, does the program continue or is it still not responding ?

When you use the time as input parameter for your game, a larger break might break your code. E.g. if you expect an average frame duration of 20-100ms and suddenly you got several seconds, your program could run into trouble.

The program continues after closing the JOptionPane.

If you enter the input fast enough, the game doesn't even go unresponsive at all, it's only when you take a few seconds to get the input.

Bump

This topic is closed to new replies.

Advertisement