I have tried too many things to solve it without any results :
comparing a password field ..
Well I know that for example in a JTextField :
JTextField.getText() //not preferable but it returns a string and this is the good side.
But I have tried both of those : (on runtime i fill the password field with "123")
> jLabel1.setText(jTextField1.getText()); //print the "123"
> if(jTextField1.getText() == "123") //FALSE !!
Of course I have tried to put it in a string, and to be sure that the 123 are only '123' without any thing else !
Now I used also to check the getpassword method like that :
char pass = jTextField1.getPassword();
and I have tried every thing ! .. char contains 1 , char -> 2 , char -> 3 ... but they r never equals to their values , and when putting them in a string and makinf the if(str=="123") the result is false forever ..
I don't know what is the mistake in this .. it printes them correctly, output them and all , but they r not equal to their equivalent values so what ?
Thanks for answer .
01-31-2007, 07:28 PM
dont use == when comparing string. use the .equals(String str) method
01-31-2007, 09:09 PM
== will compare the Strings memory addresses, not their values.
02-01-2007, 06:11 AM
Thank you anubis and Phalex , it works but if it compares memory adresses how it works with every thing else exept the strings objects ?
02-01-2007, 06:12 AM
ah u meant "String" I see , so the string only can't compare this .