// Demonstrate Choice lists.
import java.awt.*;
import java.applet.*;
/*
  <applet code="ChoiceDemo" width=300 height=180>
  </applet>
*/

public class ChoiceDemo extends Applet {
  Choice os, browser;
  String msg = "";

  public void init() {
    os = new Choice();
    browser = new Choice();
    
    // add items to os list
    os.addItem("Windows 95");
    os.addItem("Windows NT");
    os.addItem("Solaris");
    os.addItem("MacOS");

    // add items to browser list
    browser.addItem("Netscape 1.1");
    browser.addItem("Netscape 2.x");
    browser.addItem("Internet Explorer 2.0");
    browser.addItem("Internet Explorer 3.0");
    browser.addItem("Lynx 2.4");
    browser.select("Netscape 2.x");

    // add choice lists to window
    add(os);
    add(browser);
  }

  // Repaint when a selection has been made.
  public boolean action(Event evtObj, Object arg) {
    if(evtObj.target instanceof Choice) {
      repaint();
      return true;
    }
    return false;
  }

  // Display current selections.
  public void paint(Graphics g) {
    msg = "Current OS: ";
    msg += os.getSelectedItem();
    g.drawString(msg, 6, 120);
    msg = "Current Browser: ";
    msg += browser.getSelectedItem();
    g.drawString(msg, 6, 140);
  }
}