import java.awt.*; class NewButtonEx1 extends Button { private TextArea ta; public NewButtonEx1(String str, TextArea ta) { super(str); this.ta = ta; } public boolean handleEvent(Event evt) { if (evt.id == Event.ACTION_EVENT) { ta.appendText("Button " + getLabel() + " saw action...\n"); } return super.handleEvent(evt); } } class NewPanelEx1 extends Panel { private String str; private TextArea ta; public NewPanelEx1(String str, TextArea ta) { super(); this.str = str; this.ta = ta; } public Insets insets() { return new Insets(5, 5, 5, 5); } public void paint(Graphics g) { g.drawRect(0, 0, size().width - 1, size().height - 1); } public boolean handleEvent(Event evt) { if (evt.id == Event.ACTION_EVENT) { ta.appendText("Panel " + str + " saw action...\n"); } else if (evt.id == Event.MOUSE_DOWN) { ta.appendText("Panel " + str + " saw mouse down...\n"); } return super.handleEvent(evt); } } public class Example1 extends java.applet.Applet { TextArea ta = new TextArea(); public void init() { setLayout(new BorderLayout()); add("Center", ta); NewPanelEx1 p1 = new NewPanelEx1("1", ta); NewPanelEx1 p2 = new NewPanelEx1("2", ta); p2.add(new NewButtonEx1("One", ta)); p2.add(new NewButtonEx1("Two", ta)); p1.add(p2); add("South", p1); } public Dimension preferredSize() { return new Dimension(400, 230); } public Insets insets() { return new Insets(5, 5, 5, 5); } public boolean handleEvent(Event evt) { if (evt.id == Event.ACTION_EVENT) { ta.appendText("Applet saw action...\n\n"); } else if (evt.id == Event.MOUSE_DOWN) { ta.appendText("Applet saw mouse down...\n\n"); } return super.handleEvent(evt); } public static void main(String [] args) { Frame f = new Frame("Example 1"); Example1 ex = new Example1(); ex.init(); f.add("Center", ex); f.pack(); f.show(); } }