Hello world.
I'm trying to teach myself and I'm having trouble with this simple codes. I just want to show if the user typed the username and the password correctly, Now the problem goes like this, it displays multiple information messages if both the username and the password are incorrect or if they are both null. And also, at line 36 I'm having trouble too. Please guide me : )
[CODE=java]String UserName = "reysean";
String Password = "lotus18";
boolean CheckUserName=f alse;
boolean CheckPassword=f alse;
//Check for username
if (txtUserName.ge tText().isEmpty ()){
JOptionPane.sho wMessageDialog( null,"Please enter username.");
CheckUserName=f alse;
txtUserName.gra bFocus();
}
else if (txtUserName.ge tText().equals( UserName)) {
CheckUserName=t rue;
}
else{
JOptionPane.sho wMessageDialog( null,"Please enter correct username.");
CheckUserName=f alse;
txtUserName.gra bFocus();
}
//Check for password
if (txtPassword.eq uals("")){
JOptionPane.sho wMessageDialog( null,"Please enter password.");
CheckPassword=f alse;
txtPassword.gra bFocus();
}
else if (txtPassword.eq uals(Password)) {
CheckPassword=t rue;
}
else{
JOptionPane.sho wMessageDialog( null,"Please enter correct password.");
CheckPassword=f alse;
txtPassword.gra bFocus();
}
if ((CheckUserName =true) && (CheckPassword= true)){
JOptionPane.sho wMessageDialog( null, "The username is: " + UserName + "\n The password is: " + Password );
}[/CODE]
Rey Sean
I'm trying to teach myself and I'm having trouble with this simple codes. I just want to show if the user typed the username and the password correctly, Now the problem goes like this, it displays multiple information messages if both the username and the password are incorrect or if they are both null. And also, at line 36 I'm having trouble too. Please guide me : )
[CODE=java]String UserName = "reysean";
String Password = "lotus18";
boolean CheckUserName=f alse;
boolean CheckPassword=f alse;
//Check for username
if (txtUserName.ge tText().isEmpty ()){
JOptionPane.sho wMessageDialog( null,"Please enter username.");
CheckUserName=f alse;
txtUserName.gra bFocus();
}
else if (txtUserName.ge tText().equals( UserName)) {
CheckUserName=t rue;
}
else{
JOptionPane.sho wMessageDialog( null,"Please enter correct username.");
CheckUserName=f alse;
txtUserName.gra bFocus();
}
//Check for password
if (txtPassword.eq uals("")){
JOptionPane.sho wMessageDialog( null,"Please enter password.");
CheckPassword=f alse;
txtPassword.gra bFocus();
}
else if (txtPassword.eq uals(Password)) {
CheckPassword=t rue;
}
else{
JOptionPane.sho wMessageDialog( null,"Please enter correct password.");
CheckPassword=f alse;
txtPassword.gra bFocus();
}
if ((CheckUserName =true) && (CheckPassword= true)){
JOptionPane.sho wMessageDialog( null, "The username is: " + UserName + "\n The password is: " + Password );
}[/CODE]
Rey Sean
Comment