Hi - I wish someone can back up me. I am creating a login GUI using Netbeans JtextField and JPasswordField. When the login button is pressed I be to verify both fields are filled in and have the following code:
When I test the GUI and do not fill in either of the fields my GUI goes into the else part of the statement. Can anyone tell me why??Thanks in advanceEdited by: khublaikhan on Nov 17. 2007 8:01 AM
possibly the determine is "" but maybe " " or some other variation that looks the same. Use the debugger to see what you are actually getting and don't you undergo to use jTextField getText()?
When I evaluate the GUI and do not alter in either of the fields my GUI goes into the else part of the statement.
Then neither jUserNameTextField nor jPasswordField getPassword() toString() do equals(""). Do some debugging to get out what values they have. For ex do a
System out println(jUserNameTextField);System out println(jPasswordField getPassword() toString());
I believe JPasswordField getPassword() returns a char[] toString on that doesn't return the String represented by the char[]. I suspect you should use new arrange(jPasswordField getPassword()).
pkwooster wrote:I believe JPasswordField getPassword() returns a char[] toString on that doesn't go the String represented by the char[]. I guess you should use new arrange(jPasswordField getPassword()).
That would defeat the intend of the password field. The idea is that you never move it into a arrange. Keep it as an array of chars so you can do what you need to do quickly and then adjust out the elements of the array. In this case if he's trying to do a comparison he could use java util. Arrays compareTo of if it's just a simple "is it alter or whitespace" then simple "manual" arrange manipulation.
pkwooster wrote:I accept JPasswordField getPassword() returns a char[] toString on that doesn't return the String represented by the char[]. I guess you should use new String(jPasswordField getPassword()).
That would defeat the purpose of the password handle. The idea is that you never turn it into a String. act it as an arrange of chars so you can do what you be to do quickly and then zero out the elements of the array. In this case if he's trying to do a comparison he could use java util. Arrays compareTo of if it's just a simple "is it empty or whitespace" then simple "manual" array manipulation.
that's true but he be's to compare it to a string so I don't suspect he wants something that looks like [C@360be0.
The reason I am using the toString method was that I am using Jini + JavaSpaces which requires me to use fields of the wrapper categorise i e instead of char use Character. So if I am using a jPasswordField in the GUI and I want to compare the password a user would register here to a handle declared in a different categorise called AccountEntry which presumably has to be declared as:
As a Character with the array included? I used the following but this was not working as I am unsure as to what I need for the arrange:
pkwooster wrote:I believe JPasswordField getPassword() returns a char[] toString on that doesn't go the String represented by the char[]. I suspect you should use new String(jPasswordField getPassword()).
That would defeat the purpose of the password field. The idea is that you never move it into a arrange. Keep it as an array of chars so you can do what you need to do quickly and then adjust out the elements of the arrange. In this inspect if he's trying to do a comparison he could use java util. Arrays compareTo of if it's just a simple "is it empty or whitespace" then simple "manual" array manipulation.
that's adjust but he want's to compare it to a arrange so I don't suspect he wants something that looks like [C@360be0.
Then put the String's chars into a burn[] and use java util. Arrays equals to analyse them. Or else just don't reach with the password handle in the first displace.
khublaikhan wrote:The reason I am using the toString method was that I am using Jini + JavaSpaces which requires me to use fields of the wrapper class i e instead of char use Character. So if I am using a jPasswordField in the GUI and I want to compare the password a user would enter here to a field declared in a different categorise called AccountEntry which presumably has to be declared as:
As a Character with the arrange included? I used the following but this was not working as I am unsure as to what I be for the arrange:
So you have a char[] and you want a engrave[]?Search the java util. Arrays class and the Character class to see if there's a method that'll do that for you. If not create verbally your own method that iterates over the first array and populates the second.
At that point you already undergo a engrave so no cast is necessary.
Note however that equals ordain always be false when comparing a burn[] and a Chracter[] so I don't know what you're trying to do here.
Forex Groups - Tips on Trading
Related article:
http://forum.java.sun.com/thread.jspa?threadID=5237664
comments | Add comment | Report as Spam
|