1import java.applet.*;
2import java.awt.*;
3import java.awt.event.*;
4
5public class AnAppletWithButtons extends Applet implements ActionListener {
6 public void init() {
7 button1 = new Button("Button 1");
8 add(button1);
9 button1.addActionListener(this);
10
11 button2 = new Button("Button 2");
12 add(button2);
13 button2.addActionListener(this);
14 }
15
16 public void actionPerformed(ActionEvent e) {
17 if (e.getSource() == button1)
18 System.out.println("Button 1 was pressed");
19 else
20 System.out.println("Button 2 was pressed");
21 }
22
23 Button button1, button2;
24}
25