0

对于使用带有消息对话框弹出框的客户端验证为空的文本字段,您如何对其进行integer编码double

我实现了String empname但是我似乎无法弹出一个对话框empidpayrate任何建议将不胜感激。

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");
4

1 回答 1

0

尝试

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

如果用户输入除 之外的任何内容int,这应该会打开对话框。对于payrate.

double payrate;
try {
    payrate = Double.parseDouble(jtfPayRate.getText().trim());
} catch (NumberFormatException nfe) {
    JOptionPane.showMessageDialog(null, "Please Enter Your Pay Rate");
}
于 2014-09-01T08:36:48.110 回答