import java.awt.*;
import java.awt.event.*;

    // Display a pair of labelled text fields.
    // Detect when the Return key is typed in either field.
public class LoginFrame extends Frame implements ActionListener {
    public LoginFrame(){
        final int width = 600, height = 75;
        setSize(width,height);
        setBackground(Color.white);

        // How many characters may be entered in either field.
        final int fieldWidth = 10;

        // A panel for the label and field pairs
        Panel panel = new Panel();

        Label nameLabel = new Label("Name: ");
        TextField nameField = new TextField("",fieldWidth);
        Label passwordLabel = new Label("Password: ");
        TextField passwordField = new TextField("",fieldWidth);
        // Hide passwords.
        passwordField.setEchoChar('?');

        // Let us know about action events.
        nameField.addActionListener(this);
        passwordField.addActionListener(this);
        // Group the labels and the fields as a unit.
        panel.add(nameLabel);
        panel.add(nameField);
        panel.add(passwordLabel);
        panel.add(passwordField);
        // Add to the Frame.
        add(panel,"North");

    }

    public void actionPerformed(ActionEvent e){
        Object source = e.getSource();
        if(source instanceof TextField){
            TextField field = (TextField) source;

            if(field.echoCharIsSet()){
                System.out.println("The password is secret!");
            }
            else{
                System.out.println("Name = "+field.getText());
            }
        }
    }
}
