import java.awt.*; import java.awt.event.*; import java.applet.*; public class Name extends Applet implements ActionListener { private Label myLabel; private TextField myInField; private Button myButton; private TextField myOutField; public Name() /** not really needed, since this is an applet the init() method is run when the program starts */ {} public void init() /** the applet runs this method when it is first loaded into the web browser */ { myLabel = new Label("Type your name and press the button"); myInField = new TextField(30); myButton = new Button("Enter"); myOutField = new TextField(30); add(myLabel); add(myInField); add(myButton); add(myOutField); myButton.addActionListener(this); } public void actionPerformed(ActionEvent e) /** method that handles all applet events, is called automatically when an event occurs */ { Object cause = e.getSource(); if(cause == myButton) { String yourName = new String(myInField.getText()); myOutField.setText("Hello " + yourName + "!"); } } }