Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Mar 25th, 2005, 10:25 AM   #1
balltheheed
Newbie
 
Join Date: Mar 2005
Posts: 1
Rep Power: 0 balltheheed is on a distinguished road
Question Comparing strings....

Hi everyone,
I have a small problem that I just can not work out, regarding comparing user input and pre defined variables. For some reason it just doesn't want to work!!

btnSubmit.addActionListener
	(
		new ActionListener()
		{
			//perform an action if button is pressed
			public void actionPerformed(ActionEvent e)
			{
				String enteredUsername = txtUsername.getText();
				char[] enteredPassword = txtPassword.getPassword();
				String stringToPrint = new String (enteredPassword);
					
				if (enteredUsername == username && stringToPrint == password)
				{
					//constructor to load next window
					mainUI loginNick = new mainUI();
					
					//close the window onjce the person is logged in
					dispose();
				}
					
				else
				{
					System.out.println("Enter your bloody details correctly");
	                         }

			}
		}
	);

Can someone please tell me what I am doing wrong?

Ps System.out's show they are the same!?

Last edited by balltheheed; Mar 25th, 2005 at 10:30 AM.
balltheheed is offline   Reply With Quote
Old Mar 25th, 2005, 11:21 AM   #2
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 381
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
if (enteredUsername.equals("username") && stringToPrint.equals("password"))

you can't compare to strings the same way as you do with integers. You have to use equals()
__________________
Don't take life too seriously, it's not permanent !
xavier is offline   Reply With Quote
Old Mar 25th, 2005, 1:12 PM   #3
Java_Student
Newbie
 
Join Date: Mar 2005
Posts: 1
Rep Power: 0 Java_Student is on a distinguished road
you can also use equalsIgnoreCase() if you don't want the username and password to be case sensitive
Java_Student is offline   Reply With Quote
Old Apr 8th, 2005, 3:26 AM   #4
Gigabytee
Newbie
 
Join Date: Apr 2005
Posts: 17
Rep Power: 0 Gigabytee is on a distinguished road
Lightbulb Extra Information

For more Information on Interesting methods of the class string go to:
Java API: String
------
Gigabytee
Gigabytee is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:52 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC