1 Replies - 340 Views - Last Post: 31 January 2013 - 11:27 PM Rate Topic: -----

#1 madcrazydrumma  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 31-January 13

Trying to get input text from JPasswordField

Posted 31 January 2013 - 09:51 PM

Hello everyone!

I am struggling with an annoying piece of code, for the login of my launcher.

I have create a JPasswordField, variable 'password' and I want to get the text the user has typed in.

I tried to do this, but it doesn't seem to get the value...

                login.addActionListener(new ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
		    	char[] passes = password.getPassword();
		    	String p = new String(passes);
		    	
		    	if(username.getText() == "test" && p.equals("test"))
		    	{
		    		JOptionPane.showMessageDialog(null, "Correct Details!");
		    	}
			} 
		});



Is This A Good Question/Topic? 0
  • +

Replies To: Trying to get input text from JPasswordField

#2 farrell2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 866
  • View blog
  • Posts: 2,657
  • Joined: 29-July 11

Re: Trying to get input text from JPasswordField

Posted 31 January 2013 - 11:27 PM

Change

username.getText() == "test"



to

username.getText().equals("test");



and try it.

Always use equals() for Strings.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1