Jump to content

  • Log In with Google      Sign In   
  • Create Account


JOptionPane inside of switch statement?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
6 replies to this topic

#1 stein102   Members   -  Reputation: 475

Like
0Likes
Like

Posted 25 March 2013 - 10:14 PM

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;
				}

 



Sponsor:

#2 stein102   Members   -  Reputation: 475

Like
0Likes
Like

Posted 26 March 2013 - 12:22 AM

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?



#3 Ashaman73   Crossbones+   -  Reputation: 6753

Like
0Likes
Like

Posted 26 March 2013 - 01:41 AM

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.



#4 stein102   Members   -  Reputation: 475

Like
0Likes
Like

Posted 26 March 2013 - 02:08 AM

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.



#5 Ashaman73   Crossbones+   -  Reputation: 6753

Like
0Likes
Like

Posted 26 March 2013 - 02:52 AM

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.



#6 stein102   Members   -  Reputation: 475

Like
0Likes
Like

Posted 26 March 2013 - 03:09 AM

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.



#7 stein102   Members   -  Reputation: 475

Like
0Likes
Like

Posted 27 March 2013 - 12:26 AM

Bump






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS