import java.awt.*; import java.awt.event.*; import java.applet.*; public class ChoiceApplet02 extends Applet { Choice theChoice = new Choice(); TextField theTextField = new TextField(20); public void init() { theChoice.addItem("Choice item # 1"); theChoice.addItem("Choice item # 2"); theChoice.addItem("Choice item # 3"); add(theChoice); add(theTextField); theTextField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("ENTER----->ActionListener"); String mName = e.getActionCommand(); System.out.println("mName: " + mName); System.out.println("EXIT------>ActionListener"); } }); } public boolean action(Event event, Object arg) { System.out.println("ENTER----->action"); if (event.target == theChoice) System.out.println(theChoice.getSelectedItem() + " selected"); System.out.println("EXIT------>action"); return true; } public boolean handleEvent(Event e) { System.out.println(e.toString()); return super.handleEvent(e); } public static void main(String args[]) { Applet theApplet = new ChoiceApplet02(); appletFrame theFrame = new appletFrame(); theFrame.add("Center", theApplet); theApplet.init(); theFrame.resize(500,300); theFrame.show(); theApplet.start(); } } class appletFrame extends Frame { public boolean handleEvent(Event e) { if (e.id == Event.WINDOW_DESTROY) { this.hide(); this.dispose(); System.exit(0); return true; } else return super.handleEvent(e); } }