isNumeric
public void actionPerformed(ActionEvent e) { String strPL=fxplText.getText(); String strCS=fxcsText.getText(); if(strPL.equals("") || strCS.equals("")){ ...//提示不能为空 }else{ if(isNumeric(strPL) && isNumeric(strCS)){ int iPL= Integer.parseInt(strPL); int iCS= Integer.parseInt(strCS); ...// ...//提示成功 }else{ ...//提示输入必须为数字 } } } //方法一:用JAVA自带的函数 public static boolean isNumeric(String str){ for (int i = str.length();--i>=0;){ if (!Character.isDigit(str.charAt(i))){ return false; } } return true; }

浙公网安备 33010602011771号