need help with validation..
i wont to includ a validation for these...but i dont no how !!?
Code:
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 ..!!!!!!???
Re: need help with validation..
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/G...ptionpane.html
Re: need help with validation..
Otherwise if you are trying to make sure you have a valid number, take a look at Integer.parseInt(String) and make note that it can throw NumberFormatException. To handle that, try taking a look at handling exceptions. I am not sure what you were asking however.