Results 1 to 2 of 2
Thread: Problem JOptionPane try catch
- 07-10-2009, 04:25 PM #1
Member
- Join Date
- Jul 2009
- Posts
- 1
- Rep Power
- 0
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
-
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.
Similar Threads
-
[SOLVED] JOptionPane.ShowConfirmDialog() problem
By jon80 in forum New To JavaReplies: 15Last Post: 06-03-2009, 02:37 AM -
how to catch two exceptions in one catch()?
By arnab321 in forum New To JavaReplies: 1Last Post: 11-06-2008, 10:54 AM -
JOptionPane problem
By MomenT in forum New To JavaReplies: 22Last Post: 10-02-2008, 05:56 PM -
[SOLVED] On Exit JoptionPane problem
By Mir in forum New To JavaReplies: 24Last Post: 07-15-2008, 07:39 AM -
Problem with JOptionPane.showInputDialog()
By romina in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 05:33 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks