//AppletButtonEvent.java import java.applet.*; import java.awt.*; import java.awt.event.*; public class AppletButtonEvent extends Applet implements ActionListener { TextField input,output; public void init() { Label prompt = new Label("input name"); Button btn = new Button("OK"); input = new TextField(6); output = new TextField(20); add(prompt); add(input); add(btn); add(output); btn.addActionListener(this); } public void actionPerformed(ActionEvent e) { output.setText(input.getText()+",Welcome!"); } }
<html>
<body>
<applet code=AppletButtonEvent.class width=300 height=300></applet>
</body>
</html>