import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class TextFieldExample extends Applet implements ActionListener { Label nameLabel; TextField nameField; Button info, clear; public void init() { /* ******** Construct the name panel ******** */ //Create the name panel, set background to white for visibility Panel namePanel = new Panel(); namePanel.setBackground(Color.white); // Create each component of the name panel // and add it to the name panel nameLabel = new Label("Name:"); namePanel.add(nameLabel); nameField = new TextField("",30); nameField.addActionListener(this); namePanel.add(nameField); // Add the name panel to the applet. add(namePanel); /* ******** Construct the selections panel ******** */ // Create selections panel, set background to white Panel selections = new Panel(); selections.setBackground(Color.white); // Create each component of the name panel and // add it to the selections panel info = new Button("INFO"); info.addActionListener(this); selections.add(info); clear = new Button("CLEAR"); clear.addActionListener(this); selections.add(clear); // Add the selections panel to the applet. add(selections); } public void actionPerformed (ActionEvent ae) { if (ae.getSource() == nameField) { //System.out.println("Got an event from the text field nameField."); String name = ae.getActionCommand(); nameField.setText("Nice to meet you " + name + "."); } else if (ae.getSource() == info) //System.out.println("Got an event from the info button."); nameField.setText("Enter your name here, please"); else if (ae.getSource() == clear) //System.out.println("Got an event from the clear button."); nameField.setText(""); } } // class FirstGUI