Results 1 to 9 of 9
  1. #1
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default Want to validate Strings in java gui

    Hi guys,

    I want to validate an input, but i don't know what i am missing:

    Java Code:
    {
    					if (changepin.equals(savepin)){
    					System.out.println("correct");
    					}
    					else 
    						System.out.println("not correct");
    	    }
    			 }
    		}
    This is inside an actionlistener for 'Change pin' button. I want to input a password and validate it. But when I click on this button, it's showing "Not correct" without letting me input.

    I have tried, but i don't know what i am missing.

    Sorry, if I can't show you the entire code because I don't want others copying as i can be hit by plagiarism.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Want to validate Strings in java gui

    You get that message printed because the equals() method returns false.
    You need to make a small test program that compiles, executes and shows the problem.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default Re: Want to validate Strings in java gui

    Quote Originally Posted by Norm View Post
    You get that message printed because the equals() method returns false.
    You need to make a small test program that compiles, executes and shows the problem.
    Hey Norm, I have gotten somewhere with this code. I will do what you have said.

    I have a question I would like to ask.

    When I select the 'Change Password' button, I want it to let me input and then validate. I was wondering, how do I get the input first??

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Want to validate Strings in java gui

    Where do you want to enter the input? A modal dialog box would stop the execution while you do the input.
    If you don't understand my response, don't ignore it, ask a question.

  5. #5
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default Re: Want to validate Strings in java gui

    Quote Originally Posted by Norm View Post
    Where do you want to enter the input? A modal dialog box would stop the execution while you do the input.
    My program has numeric buttons and inputs are displayed on the JPasswordField.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Want to validate Strings in java gui

    Are you saying that the user's input is in the JPasswordField?
    After the user enters the data in that field and presses a button that would send you to a listener that would get the data from the field and validate it.

    If you do not enable the button that goes to the validation listener until there is data in the field, you will always have input when the listener is called.
    If you don't understand my response, don't ignore it, ask a question.

  7. #7
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default Re: Want to validate Strings in java gui

    Quote Originally Posted by Norm View Post
    Are you saying that the user's input is in the JPasswordField?
    After the user enters the data in that field and presses a button that would send you to a listener that would get the data from the field and validate it.

    If you do not enable the button that goes to the validation listener until there is data in the field, you will always have input when the listener is called.
    Yup. So, do you mean I should make a call inside the validation listener, so inputs go first, then validator goes second?

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,562
    Rep Power
    25

    Default Re: Want to validate Strings in java gui

    The user should enter the input first then his input would be available for validation.

    There is no way to know what the code should do without seeing it.
    If you don't understand my response, don't ignore it, ask a question.

  9. #9
    juxta is offline Member
    Join Date
    Nov 2011
    Posts
    30
    Rep Power
    0

    Default Re: Want to validate Strings in java gui

    Quote Originally Posted by Norm View Post
    The user should enter the input first then his input would be available for validation.

    There is no way to know what the code should do without seeing it.
    Ahh okay, I kind of got the idea now. I messed up what i said before, but it gave me a clearer idea.

Similar Threads

  1. Java method for XML validate
    By Seanryano in forum Advanced Java
    Replies: 4
    Last Post: 11-18-2011, 08:15 AM
  2. How do I validate user input from forms with Java?
    By rickywh in forum New To Java
    Replies: 2
    Last Post: 01-30-2010, 06:49 AM
  3. Validate a Zip file with java
    By peuplier in forum Advanced Java
    Replies: 1
    Last Post: 07-10-2009, 10:07 PM
  4. The java Strings
    By greenteachacha in forum Jobs Discussion
    Replies: 8
    Last Post: 04-16-2009, 05:08 AM
  5. Replies: 7
    Last Post: 05-23-2008, 03:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •