![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
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 ! |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Mar 2005
Posts: 1
Rep Power: 0
![]() |
you can also use equalsIgnoreCase() if you don't want the username and password to be case sensitive
|
|
|
|
|
|
#4 |
|
Newbie
Join Date: Apr 2005
Posts: 17
Rep Power: 0
![]() |
For more Information on Interesting methods of the class string go to:
Java API: String ------ Gigabytee |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|