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!

How close a JOptionPane in a for loop with try-catch statement?

843806Feb 28 2008 — edited Feb 28 2008
When the JOptionPane opens, I cannot close it with the close-button at the top right of the window. The cause is the for loop but I need it to get sure that the user really inputs digits and not letters. When I try to close the JOptionPane, the catch option runs, and I cannot close the JOptionPane untill I type som digits in the age textfield. Can I get through this problem?
for(;;)
			{

				try
				{
						showMessageDialog(this,null,"Input some data", CLOSED_OPTION)

						String str_name = name.getText();
						int int_age= Integer.parseInt(age.getText());		
						break; 
				}catch(NumberFormatException e)
				{
					JOptionPane.showMessageDialog(this, "Numerical value!","Error", JOptionPane.ERROR_MESSAGE);
				}
			}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 27 2008
Added on Feb 28 2008
3 comments
258 views