Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-10-2009, 05:25 PM
Member
 
Join Date: Jul 2009
Posts: 1
Rep Power: 0
jason99 is on a distinguished road
Default Problem JOptionPane try catch
import javax.swing.JOptionPane;

public class trycatch
{
public static void main(String args[])
{
boolean loop=false;
do
{
try
{

String strinput=JOptionPane.showInputDialog(null,"Enter a integer");
int input=Integer.parseInt(strinput);

}
catch(NumberFormatException ex)
{
OptionPane.showMessageDialog(null,"Invalid value entered");
loop=true;
}


}while(loop);
}
}

can some one help me solve this , the problem is once the exception is catch then the CANCEL & CLOSED OPTION cant close the JOptionPane,thanks
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 07-10-2009, 11:39 PM
Fubarable's Avatar
Moderator
 
Join Date: Jun 2008
Posts: 5,968
Rep Power: 7
Fubarable is on a distinguished road
Default
1) You'll want to set your loop variable to false at the beginning of the try block. Otherwise if you enter bad input once, you will loop forever, even if good input is given later.
2) You'll want to check if the String returned from the showInputDialog method is null or not. Play with this and you'll figure it out.

Best of luck.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] JOptionPane.ShowConfirmDialog() problem jon80 New To Java 15 06-03-2009 03:37 AM
how to catch two exceptions in one catch()? arnab321 New To Java 1 11-06-2008 11:54 AM
JOptionPane problem MomenT New To Java 22 10-02-2008 06:56 PM
[SOLVED] On Exit JoptionPane problem Mir New To Java 24 07-15-2008 08:39 AM
Problem with JOptionPane.showInputDialog() romina AWT / Swing 1 08-07-2007 06:33 AM


All times are GMT +2. The time now is 12:56 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org