/* This example demonstrates how to add a Choice menu to an applet and how to receive Choice events via the action() method. */ import java.awt.*; import java.applet.*; public class ChoiceTest extends Applet { Choice colorChoice = new Choice(); public void init() { setBackground(Color.red); colorChoice.addItem("Red"); colorChoice.addItem("Yellow"); colorChoice.addItem("Green"); colorChoice.addItem("Blue"); colorChoice.addItem("White"); colorChoice.addItem("Black"); add(colorChoice); } public boolean action(Event evt, Object arg) { if (evt.target == colorChoice) { if (((String)arg).equals("Red")) setBackground(Color.red); else if (((String)arg).equals("Yellow")) setBackground(Color.yellow); else if (((String)arg).equals("Green")) setBackground(Color.green); else if (((String)arg).equals("Blue")) setBackground(Color.blue); else if (((String)arg).equals("White")) setBackground(Color.white); else setBackground(Color.black); repaint(); return true; } return false; } }