TextField

S

sent1729

Hi all,

I my app. I have a JDialog with a Textfield , based on the text I
enter, I want to open up a new frame (just like using a password)
This is what I did for testing:

public static JTextField jtxtUserName = new JTextField();
public static JButton button = new JButton();
public NewClass(Frame owner, boolean modal){
super(owner,modal);

Container cp = getContentPane();

button.setText("Initialize");
cp.add(jtxtUserName);
jtxtUserName.setBounds(100,10,200,20);
button.setBounds(200,85,100,22);
button.addActionListener( this );
}

public void actionPerformed(ActionEvent e) {
if( e.getSource() == button )
{
if (jtxtPassword.getText().toString() == "ABCD"){
System.exit(0);
}
}

My problem is, when I run my app. and type "ABCD" for the user name and
hit the "start"button , i expect the app. to close. but it does not. if
I print out jtxtPassword.getText().toString() it shows ABCD, but the
programme does not get in to the if statement ( if
(jtxtPassword.getText().toString() == "ABCD") ).

AM I doing something wrong?

Any input will be greatly appreciated.

Thanks
Nathan.
 
M

Monique Y. Mudama

My problem is, when I run my app. and type "ABCD" for the user name and
hit the "start"button , i expect the app. to close. but it does not. if
I print out jtxtPassword.getText().toString() it shows ABCD, but the
programme does not get in to the if statement ( if
(jtxtPassword.getText().toString() == "ABCD") ).

AM I doing something wrong?

Try using .equals() instead of ==.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top