java - How to be sure about Integer value of a JTextfield? -


i have jtextfield users must enter number in that.

i want check value sure contains **integer*.*

here code:

jtextfield tex_amount=new jtextfield(); . . . string s=tex_amount.gettext();  int a=integer.parseint(s); 

the problem if user enter string in field face error: java.lang.numberformatexception. how can check value?

you can use try..catch

try{     int = integer.parseint(s); } catch(arithmeticexception e){     //handel error here  } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -