我有一個JTextField,其中用戶必須在那輸入一個號碼。如何確定JTextfield的整數值?
我想檢查一下這個值是否包含* * Integer *。 *
下面是代碼:
JTextField Tex_amount=new JTextField();
.
.
.
String s=Tex_amount.getText();
int a=Integer.parseInt(s);
的問題是,如果用戶在字段中輸入一個字符串我將與錯誤臉: java.lang.NumberFormatException。那我該如何檢查價值?
做一些驗證,其中用戶只能從鍵盤輸入數字。 – subodh 2013-04-05 07:31:18
這裏:http://stackoverflow.com/questions/11093326/restricting-jtextfield-input-to-integers限制輸入只有整數 – 2013-04-05 07:33:23
另請參閱http://stackoverflow.com/a/13424140/1076463 – Robin 2013-04-05 09:01:34