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;
}

 

posted @ 2018-01-05 18:24  sky20080101  阅读(81)  评论(0)    收藏  举报