Click to See Complete Forum and Search --> : need help with validation..


nadykool
April 25th, 2008, 05:12 PM
i wont to includ a validation for these...but i dont no how !!?


if (x==1)
{
inp =JOptionpane.showInputDialoge("Enter Number of miles')
int y= Integer.parseInt(inp);
double miles=c.KmToMiles(y);
JOptionpane.showmessageDialog(null,"Miles="+miles);

}


if (x==2)
{
inp =JOptionpane.showInputDialoge("Enter Number of km ")
int y= Integer.parseInt(inp);
double km=c.MilesToKm(y);
JOptionpane.showmessageDialog(null,"km="+km);

}




how can i do it ..!!!!!!???

Londbrok
April 26th, 2008, 03:42 AM
Code you posted does not compile. Send something that does compile, makes it well easier to see where you actually have issues. Meanwhile, check this tutorial, seems to be right down your alley.

http://www.leepoint.net/notes-java/GUI/containers/20dialogs/10joptionpane.html

spidermo
April 27th, 2008, 02:08 AM
Otherwise if you are trying to make sure you have a valid number, take a look at Integer.parseInt(String) (http://java.sun.com/j2se/1.3/docs/api/java/lang/Integer.html#parseInt(java.lang.String)) and make note that it can throw NumberFormatException. To handle that, try taking a look at handling exceptions (http://java.sun.com/docs/books/tutorial/essential/exceptions/handling.html). I am not sure what you were asking however.