java - How to be sure about Integer value of a JTextfield? -
this question has answer here:
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
Post a Comment