If Else statement
Posted by ~Ray @ 2008-06-13 06:07:07
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 ensure both fields are filled in and have the following label:
When I evaluate the GUI and do not alter in either of the fields my GUI goes into the else move 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 have to use jTextField getText()?
When I test 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 go 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 arrange represented by the burn[]. I suspect you should use new arrange(jPasswordField getPassword()).
That would defeat the intend of the password field. The idea is that you never turn 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 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.
pkwooster wrote:I believe JPasswordField getPassword() returns a char[] toString on that doesn't return the String represented by the burn[]. I suspect you should use new arrange(jPasswordField getPassword()).
That would defeat the purpose of the password field. The idea is that you never move it into a String. Keep it as an array of chars so you can do what you need to do quickly and then zero out the elements of the array. 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 be's to analyse 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 analyse the password a user would enter here to a field declared in a different class called AccountEntry which presumably has to be declared as:
As a engrave with the array included? I used the following but this was not working as I am unsure as to what I be for the array:
pkwooster wrote:I believe JPasswordField getPassword() returns a burn[] toString on that doesn't return the arrange represented by the char[]. I guess you should use new String(jPasswordField getPassword()).
That would blackball the purpose of the password handle. The idea is that you never move it into a String. Keep it as an array of chars so you can do what you need to do quickly and then zero 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" arrange manipulation.
that's adjust but he be's to compare it to a string so I don't guess he wants something that looks desire [C@360be0.
Then put the String's chars into a char[] and use java util. Arrays equals to compare them. Or else just don't reach with the password handle in the first place.
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 register here to a field declared in a different class 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 need for the arrange:
So you undergo a burn[] and you be a Character[]?examine the java util. Arrays categorise and the Character categorise 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 arrange and populates the back up.
At that point you already have a Character so no cast is necessary.
say however that equals will always be false when comparing a char[] and a Chracter[] so I don't know what you're trying to do here.[ADVERTHERE]Related article:
http://forum.java.sun.com/thread.jspa?threadID=5237664
0 Comments:
No comments have been posted yet!
|