Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help on JButton

Status
Not open for further replies.

youdaman

Technical User
Dec 26, 2001
66
0
0
US
I would like to capture the input after the <enter> key is hit rather than using a JButton. Anyone have ideas on how I could do this? Thanks for your help!
 
Below is the code I am using. I have a local web site setup and and trying to password protect it. This brings up the applet but even if I write in the correct value(Test) for field myTextField, I always get dropped to the else statement. Thanks.....

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JPasswordA extends JApplet implements ActionListener
{//1
JLabel myPassword = new JLabel(&quot;Enter A Password&quot;);
JTextField myTextField = new JTextField(&quot;&quot;, 15);
Font myFont = new Font(&quot;Arial&quot;, Font.BOLD + Font.ITALIC, 18);
Container con = getContentPane();
FlowLayout flow = new FlowLayout();
JLabel status = new JLabel(&quot;&quot;);

public void init()
{
con.setLayout(flow);
con.add(myPassword);
con.add(myTextField);
con.add(status);
myTextField.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{

Object source = e.getSource();
String newText;
newText= myTextField.getText();

if (newText.equals(&quot;Test&quot;))
{

// you have an error
status.setText(&quot;OK&quot;);
}
else
{
// get the data
status.setText(&quot;Password is incorrect&quot;);
}
}

}//1
 
Weird. I don't! it outputs &quot;OK&quot; next to the password TextField.
 
I got the same results as thekobbler. Maybe try equalsIgnoreCase?

Just a thought.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top