Computer Science 122
List Box Example

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

// Applet that draws different colored circles.
public class ChoicesList extends Applet
{
    private List choices;
    private Graphics g;

    public void init ()
    {
        choices = new List (3, false);
        choices.add ("Red");
        choices.add ("Yellow");
        choices.add ("Green");
        add (choices);
        choices.addItemListener (new listListener ());
        g = getGraphics ();
    } // method init

    class listListener implements ItemListener
    {
        public void itemStateChanged (ItemEvent event)
        {
            String choice = choices.getSelectedItem ();
            int y = 0;
            if (choice.equals ("Red"))
            {
                y = 50;
                g.setColor (Color.red);
            }
            else if (choice.equals ("Yellow"))
            {
                y = 100;
                g.setColor (Color.orange);
            }
            else if (choice.equals ("Green"))
            {
                y = 150;
                g.setColor (Color.green);
            }
            g.fillOval (50, y, 30, 30);
        } // method itemStateChanged
    } // class listListener
} // class ChoicesList