Results 1 to 6 of 6
  1. #1
    Rasmase is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Exclamation Password field dont work!

    I really got a problem here. The password field dont seem to work!
    The current script is:


    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    if ((jPasswordField1.getText()) = "Hello"){
    this.setVisible(false);
    new Admin().setVisible(true);
    }
    }

    I don't want anything fancy encrypt, i just want it to work!
    My IDE shows a error message:

    unexpected type:
    required: variable
    found: value

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,939
    Rep Power
    8

    Default Re: Password field dont work!

    First off, = is assignment, == is comparison.

    Secondly, don't use == to compare Strings. Use the .equals() method instead. The == operator compares whether two variables hold the same reference. The .equals() method compares the actual content of the instances.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Password field dont work!

    That shouldn't even compile:

    Java Code:
    if (suchAndSuch = "Hello") {
      ...
    }
    Also, I thought that getText() was deprecated for JPasswordField.

    You will want to change "Hello" into a char array and compare the arrays, which I think you'll need to do element by element. Either that convert the char array held by the JPasswordField obtained via getPassword() into a String via new String(myCharArray), but I don't recommend the latter as it's not as secure. And if you do this, you'll need to compare the two Strings with equals(...), not with ==.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Password field dont work!

    Also, are you going to reply to us? You didn't reply to any of the folks who helped you in your last thread. We don't get paid so your replies help "pay" us.

  5. #5
    Rasmase is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

    Default Re: Password field dont work!

    At last time my network was down some days, couldn't do anything and totally forgot.
    Sorry for that. Right now i am testing the different ways.

  6. #6
    Rasmase is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

Similar Threads

  1. password Field String
    By mudassir07 in forum NetBeans
    Replies: 1
    Last Post: 02-19-2011, 08:18 AM
  2. actions dont work properly, calculator
    By lordjb in forum New To Java
    Replies: 14
    Last Post: 02-03-2011, 07:00 AM
  3. this programme dont work as I want Help me!!
    By pinar in forum New To Java
    Replies: 2
    Last Post: 10-26-2010, 11:27 PM
  4. how to check password for 3 times enterd wrong password
    By sk.mahaboobbhasha@gmail.c in forum New To Java
    Replies: 2
    Last Post: 11-14-2008, 07:53 PM
  5. How to check password of a jsp/html with the password of Database(mysql) #1
    By sk.mahaboobbhasha@gmail.c in forum Java Servlet
    Replies: 2
    Last Post: 11-14-2008, 01:11 PM

Tags for this Thread

Posting Permissions

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