If Else statement
Posted by ~Ray @ 2008-06-13 06:07:10
Hi - I hope someone can help me. I am creating a login GUI using Netbeans JtextField and JPasswordField. When the login add is pressed I want to ensure both fields are filled in and undergo the following label:
When I evaluate the GUI and do not fill in either of the fields my GUI goes into the else part of the statement. Can anyone express me why??Thanks in advanceEdited by: khublaikhan on Nov 17. 2007 8:01 AM
possibly the value 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 test the GUI and do not fill in either of the fields my GUI goes into the else move 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 burn[] toString on that doesn't go the arrange represented by the burn[]. I suspect you should use new String(jPasswordField getPassword()).
pkwooster wrote:I believe JPasswordField getPassword() returns a char[] toString on that doesn't return the String represented by the burn[]. I guess you should use new String(jPasswordField getPassword()).
That would blackball the purpose of the password field. The idea is that you never turn it into a arrange. act 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 empty or whitespace" then simple "manual" arrange manipulation.
pkwooster wrote:I believe JPasswordField getPassword() returns a burn[] toString on that doesn't return the String represented by the burn[]. I guess you should use new String(jPasswordField getPassword()).
That would defeat the intend of the password handle. The idea is that you never turn 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 alter or whitespace" then simple "manual" array manipulation.
that's true but he want's to compare it to a string so I don't guess 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 class i e instead of char use Character. So if I am using a jPasswordField in the GUI and I be to compare 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 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 array:
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 blackball the intend of the password field. 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 alter or whitespace" then simple "manual" arrange manipulation.
that's true but he want's to analyse it to a arrange so I don't guess he wants something that looks desire [C@360be0.
Then put the String's chars into a burn[] and use java util. Arrays equals to compare them. Or else just don't reach with the password field 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 be to analyse 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 array included? I used the following but this was not working as I am unsure as to what I be for the arrange:
So you undergo a char[] and you want a Character[]?Search the java util. Arrays categorise 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 arrange and populates the back up.
At that point you already have a engrave so no direct 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!
|