Put Circles On Canvas

import java.awt.*;

class Circle
{
   Color color;
   int left, top;
   int diameter;
   Graphics graphics;

   public Circle(int dia, int x, int y, Graphics g)
   {
      diameter = dia;
      left = x;
      top  = y;
      color = Color.blue;
      graphics = g;
   }

   public void setColor(Color c) { color = c; }

   public void draw()
   {
      graphics.setColor(color);
      graphics.fillOval(left,top,diameter,diameter);
   }
}

class CircleDB
{
   int index;
   Circle circles[];

   public CircleDB ()
   {
      circles = new Circle[100];
      index = 0;
   }

   public void add (Circle c) { circles[index++] = c;  }

   public Circle top() { return circles[index-1]; }

   public void draw ()
   {
      for (int i=index-1 ; i >= 0 ; i--) circles[i].draw();
   }
}

public class Circles extends Frame
{
   Button circle, red, green, blue;
   CircleDB cdb;
   Panel drawArea;

   public Circles ()
   {
      cdb = new CircleDB();
      setLayout(new BorderLayout());
      Panel p = new Panel();
      p.setLayout(new GridLayout(16,1));
      p.add(circle = new Button("Circle"));
      p.add(new Label(""));
      p.add(red    = new Button("Red"));
      p.add(green  = new Button("Green"));
      p.add(blue   = new Button("Blue"));
      add ("East", p);
      drawArea = new Panel();
      drawArea.setBackground(Color.white);
      add ("Center", drawArea);
   }

   public boolean action(Event evt, Object obj)
   {
      if (evt.target.equals(circle))
         cdb.add(new Circle(50,100,100,drawArea.getGraphics()));
      else
      if (evt.target.equals(red))
         cdb.top().setColor(Color.red);
      else
      if (evt.target.equals(green))
         cdb.top().setColor(Color.green);
      else
      if (evt.target.equals(blue))
         cdb.top().setColor(Color.blue);
      cdb.draw();

      return super.action(evt,obj);
   }


   public static void main (String arg[])
   {
      Circles c = new Circles();
      c.resize(500,400);
      c.show();
   }
}