我有一个用于注册页面的简单密码和文本区域检查器。这里所有的文本区域都必须被填充,否则弹出 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 ;
}
最佳答案
尝试使用以下代码片段。第二个 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;
}
关于Java注册简单检查器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49459811/