我正在尝试设置确认密码的验证,并且所有文本字段都必须包含值。我只是初学者先生,我正在练习建立一个登录和注册程序。
对英语来说很难说英语不是很好。
我的问题是我的代码没有运行FINE。它一直在告诉"填补空间"
String username = usernamefield.getText();
String password = passwordfield.getText();
String cpassword = cpasswordfield.getText();
if ((username != null) || (password != null) || (cpassword != null)) {
if (password == cpassword) {
db.insertData(username, password);
JOptionPane.showMessageDialog(null, "data has been entered");
}
else {
JOptionPane.showMessageDialog(null, "Please Fill the spaces");
}
}
else if (password != cpassword) {
JOptionPane.showMessageDialog(null, "Password Mismatch");
}
答案 0 :(得分:0)
if((username != null) || (password != null) || (cpassword != null) ){
if(password.equals(cpassword)){
db.insertData(username, password);
JOptionPane.showMessageDialog(null, "data has been entered");
}else {
JOptionPane.showMessageDialog(null, "Password Mismatch");
}
} else {
JOptionPane.showMessageDialog(null, "Please Fill the spaces");
}
试试这段代码。您应该使用equals()而不是==进行字符串比较