[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Using getText() with a JTextField component?

When you use "==" on objects, you are comparing whether they point to the
same object or not.  Use the equals() from class String to compare Strings.

Jason R. Kretzer

----- Original Message -----
From: "D. Michael Nelson" <dmn1@bellsouth.net>
To: <ajug-members@www.ajug.org>
Cc: "Suhas Kelkar" <uwinstructor@yahoo.com>
Sent: Wednesday, August 01, 2001 1:41 AM
Subject: Using getText() with a JTextField component?

> Hello,
> I am using the getText() JTextComponent method to retrieve a string form a
> JTextField component.  The problem that I am getting is the string is
> returned back, but it does pass a comparsion check when I compared it to
> another string:
> file://ie lets say the string entered in the text field is "Mike"
> String sName = m_nameTF.getText().trim();
> file://The following line works - prints "Mike
> System.out.println(sName);
> file://This condition fails
> if (sName == "Mike")
>   System.out.println("yes");
> Any suggestions?