KeyListenerr on a JPasswordField
I have a program where I want someone to enter the password, and when they press enter it does stuff. The problem is I can't check if they pressed enter because the getKeyCode() method in KeyEvent always returns 0 on a JPasswordField. Is there a way I could check for enter and get around that? Will it work if I just use a JTextField with setEchoChar('*');? Thanks.
[376 byte] By [
zachvaca] at [2007-10-1 0:50:57]

JFrame f = new JFrame();
JPasswordField p = new JPasswordField();
p.addActionListener( new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.out.println( "Hi" );
}
} );
f.add( p );
f.pack();
f.show();
mlka at 2007-7-8 1:06:32 >

Now that you are working on Swing programs you are past the "New to Java Technology" and should probably be posting Swing related questions in the Swing forum.
Don't use a KeyListener, use an ActionListener. "How to Write an Action Listener":
http://java.sun.com/docs/books/tutorial/uiswing/events/actionlistener.html