2014-09-01 3 views
0

메시지 대화 상자 팝업 상자가있는 클라이언트 측 유효성 검사를 사용하여 비어있는 텍스트 필드의 경우 integerdouble에 대해 어떻게 코딩합니까?Java 클라이언트/서버 유효성 검사 : jtextfield가 비어 있으면?

String empname을 구현했지만 empidpayrate에 대한 대화 상자 팝업을 만들 수 없는데 어떤 제안이라도 대단히 감사하겠습니다. 사용자가 int 아무것도하지만 들어갔을 경우

String empname = jtfEname.getText(); 
    //If no text is entered display pop up dialog box. 
if(empname.length()==0) 
    JOptionPane.showMessageDialog(null, "Please Enter Your Name"); 

int empid = Integer.parseInt(jtfEid.getText().trim()); 
    //If no id is entered display pop up dialog box. 
if (empid.equals("")) 
    JOptionPane.showMessageDialog(null, "Please Enter Your Id"); 

double payrate = Double.parseDouble(jtfPayRate.getText().trim()); 
    //If no payrate is entered display pop up dialog box 
if (payrate.equals("")) 
    JOptionPane.showMessageDialog(null, "Please Enter Your Pay Rate"); 

답변

0

int empid; 
try { 
    empid = Integer.parseInt(jtfEid.getText().trim()); 
} catch(NumberFormatException nfe) { 
    JOptionPane.showMessageDialog(null, "Please Enter Your Id"); 
} 

을 시도,이 대화 상자를 열어야합니다. payrate도 마찬가지입니다.

double payrate; 
try { 
    payrate = Double.parseDouble(jtfPayRate.getText().trim()); 
} catch (NumberFormatException nfe) { 
    JOptionPane.showMessageDialog(null, "Please Enter Your Pay Rate"); 
} 
+0

귀하의 의견을 잘 부탁드립니다. 멋진 하루 되십시오. – CaseyT

+0

@CaseyT 문제 없습니다. 도와 줄 수있어서 기뻐. :) – lxcky