Java注册简单检查器

时间:2018-03-24 00:00:51

标签: java passwords

我有一个简单的密码和文本区域检查器用于注册页面。这里必须填写所有文本区域,否则弹出JOptionPane。并且密码和重新输入的密码(确认密码)应该相等,否则警告。

我不知道该怎么做。

代码:

    private boolean check()  {
    boolean isEmpty=false;

    if(nickNametxt.getText().equals("") || pwdTxt.getText().equals("") || 
      logintxt.getText().equals("") || rePwdTxt.getText().equals("")){
        JOptionPane.showMessageDialog(null, "Please fill all the fields before proceeding");
    if (pwdTxt != rePwdTxt){ 
        JOptionPane.showMessageDialog(null, "Wrong Password");
    }
    isEmpty = true ;
    }

    return isEmpty ;
}

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码段。第二个if条件已从!=修改为.equals为!=将验证对象引用。

private boolean check(){
    boolean isEmpty = false;
    String nickName = nickNametxt.getText();
    String login    = logintxt.getText();
    String pwd      = pwdTxt.getText();
    String rePwd    = nickNametxt.getText();

    isEmpty = true;
    if(!((null != nickName && !nickName.isEmpty()) && (null != login && !login.isEmpty()) 
            && (null != pwd && !pwd.isEmpty()) && (null != rePwd && !rePwd.isEmpty()))){
        JOptionPane.showMessageDialog(null, "Please fill all the fields before proceeding");
        isEmpty = true;
    }else if(!pwd.equals(rePwd)){ 
        JOptionPane.showMessageDialog(null, "Wrong Password");
        //Depending on your usecase - place it here or not
        //isEmpty = true;
    }
    return isEmpty;
}