here is a snippet from my code, my jbutton action listener

private void jButton1_actionPerformed(ActionEvent e)
	{
		System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
		String username = new String(jTextuser.getText());
		String password = new String(jTextpass.getText());
		String passwordconfirm = new String(jTextpassconfirm.getText());
		String email = new String(jTextemail.getText());
		String emailconfirm= new String(jTextemailconfirm.getText());
		
		
		if(username.equals("") || password.equals("") || passwordconfirm.equals("") || email.equals("") || emailconfirm.equals("")) {
		        JLabel errorFields = new JLabel("<HTML><FONT COLOR = Black>You must fill out all fields to complete your registration.</FONT></HTML>");
			JOptionPane.showMessageDialog(null,errorFields); 
			jTextpass.setText("");
	   		jTextpassconfirm.setText("");
                }else if (password != passwordconfirm){
			JLabel errorFields2 = new JLabel("<HTML><FONT COLOR = Black>Your password fields are not the name.</FONT></HTML>");
			JOptionPane.showMessageDialog(null,errorFields2); 
			jTextpass.setText("");
   		        jTextpassconfirm.setText("");
		}else if (emailconfirm != email){
			JLabel errorFields2 = new JLabel("<HTML><FONT COLOR = Black>Your email address fields are not the name.</FONT></HTML>");
			JOptionPane.showMessageDialog(null,errorFields2); 
			jTextpass.setText("");
   		        jTextpassconfirm.setText("");
		}else{
			JLabel errorFields2 = new JLabel("<HTML><FONT COLOR = Black>Success!</FONT></HTML>");
			JOptionPane.showMessageDialog(null,errorFields2); 
			
		}
	}

even when my password fields are the same, i get my message telling me that they are not?

what am i doing wrong here?

Recommended Answers

All 5 Replies

Turn around your validation, instead of checking if is empty and passwords not equal check for true of passwords equal and email not being empty (then you logged) after it run other checks such as passwords not equal and email empty.
In this simple(I say simple as in real life there will be more complex validations to do) always go for "pass" scenario and only after that work on possible fails

Turn around your validation, instead of checking if is empty and passwords not equal check for true of passwords equal and email not being empty (then you logged) after it run other checks such as passwords not equal and email empty.
In this simple(I say simple as in real life there will be more complex validations to do) always go for "pass" scenario and only after that work on possible fails

sorry, either i did not understand your response or this did not solve my problem

i turned around my validation process as you said...

I even set it to print out both strings....

password and passwordconfirm

I then set it to print out a boolean (password == passwordconfirm)

It printed out "password" and "password"....
They were identical.

But the boolean printed out false?

What is going on here?

Well done. My advise was leading you to this. Why? If you had first check for all entry are as expected sample

if(pass == confirmPass && email !=empty)

you would be curious why on earth is "==" not working and therefore you would have come to conclusion as many before that you need to use equal

if(pass.equals(confirmPass))

It is better if you search and learn instead of handling out you directly the answer (my opinion).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.