When we design the registration module, we often have to verify that two times the password is consistent, then how to use JPasswordField implementation?
First, the GUI interface is designed:
Implementation 1: Use the GetText () method to obtain JPasswordField content, but this method has been deprecated. Also, simply put, the difference between equals () and "= =" Compares an object: "Equals ()" Compares the object's "content" only, and "= =" compares the address of the object (of course, if the address is the same, the content is of course the same).
Experiment 2: Using the GetPassword () method to get JPasswordField content, but the result is a bit unexpected, why Passwordfield1.getpassword (). Equals ( Passwordfield2.getpassword ()) is it false?
Consider the GetPassword () method: The return value type is char [].
So how does the char array compare? The following method does not work.
If you turn it into a string type, the problem is solved:
So the comparison of passwords can be used as well:
See a HA Source: The two conditions shown are not satisfied, so return false.
So the question is, in addition to this method, are there any other simpler ways? Welcome Communication (Manual funny)
JPasswordField implementation of password validation in Java