import java.awt.*;
import java.applet.*;
import java.awt.event.*;
// Applet that uses check boxes to determine what circle
to draw.
public class ChoicesCheckBox extends Applet
{
private CheckboxGroup colors;
private Checkbox red, yellow, green;
private Graphics g;
public void init ()
{
colors = new
CheckboxGroup ();
red = new
Checkbox ("Red", colors, true);
this.add (red);
red.addItemListener
(new colorListener (Color.red, 50));
yellow = new
Checkbox ("Yellow", colors, false);
this.add (yellow);
yellow.addItemListener
(new colorListener (Color.orange, 100));
green = new
Checkbox ("Green", colors, false);
this.add (green);
green.addItemListener
(new colorListener (Color.green, 150));
g = getGraphics
();
} // method init
// Inner class that listens for selection
of a check box.
class colorListener implements ItemListener
{
private Color
c;
private int
y;
colorListener
(Color c, int y)
{
this.c = c;
this.y = y;
} // constructor
public void
itemStateChanged (ItemEvent event)
{
g.setColor (c);
g.fillOval (80, y, 30, 30);
} // method
itemStateChanged
} // class colorListener
} // class choices