/* This example demonstrates how to add buttons to an applet and how to receive Button events via the action() method. */ import java.awt.*; import java.applet.*; public class ButtonActionTest1 extends Applet { Button redButton = new Button("Red"); Button blueButton = new Button("Blue"); Button greenButton = new Button("Green"); Button whiteButton = new Button("White"); Button blackButton = new Button("Black"); public void init() { setBackground(Color.white); add(redButton); add(blueButton); add(greenButton); add(whiteButton); add(blackButton); } public boolean action(Event evt, Object arg) { if (evt.target instanceof Button) { if (evt.target == redButton) setBackground(Color.red); else if (evt.target == blueButton) setBackground(Color.blue); else if (evt.target == greenButton) setBackground(Color.green); else if (evt.target == whiteButton) setBackground(Color.white); else setBackground(Color.black); repaint(); return true; } return false; } }