如何检查JPasswordField是否为空



与此代码相反的是什么-->password.getPassword().length == 0

就像你检查它是否装满了而不是空的。

JButton confirm = new JButton("Sign Up");
confirm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
UserInfo a = new UserInfo();
/*here is my problem I want it to Check if someone inputted a password so I can 
proceed to open the second frame */

if(!firstname.getText().trim().isEmpty() && !lastname.getText().trim().isEmpty() &&  password.getPassword().length == 0 && pass2.getPassword().length == 0
&& !address.getText().trim().isEmpty() )

a.frame2.setVisible(true);
frame.dispose(); 


if(firstname.getText().trim().isEmpty()) {
missingfirst.setText("Please Add Your First Name.");

}
if(lastname.getText().trim().isEmpty()) {
missinglast.setText("Please Add Your Last Name.");
}
if(password.getPassword().length == 0) {
missingpass.setText("Please Add A Password.");
}
if(pass2.getPassword().length == 0) {
missingrepass.setText("Please Re-Type Your Password.");
}
if(address.getText().trim().isEmpty()) {
missingadd.setText("Please Enter An Address.");
}

else if (!(password.getPassword().equals(pass2.getPassword()))) {
missingrepass.setText("Password Doesn't Match.");
}
}
}

使用password.getPassword().length > 0!password.getPassword().isEmpty()进行检查。

我认为在这里,你应该验证输入的密码是否是你需要的正确格式,而不是检查它是否已填写。

相关内容

  • 没有找到相关文章

最新更新