//********************************************************************
//  Dots2.java       Author: Lewis and Loftus
//
//  Demonstrates the use of a Vector to store the state of a drawing.
//********************************************************************

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

public class Dots2 extends Applet implements MouseListener
{
   private final int APPLET_WIDTH = 200;
   private final int APPLET_HEIGHT = 100;
   private final int RADIUS = 6;

   private Point clickPoint = null;
   private Vector pointList;
   private int count;

   //-----------------------------------------------------------------
   //  Creates a Vector object to store the points.
   //-----------------------------------------------------------------
   public void init()
   {
      pointList = new Vector();
      count = 0;

      addMouseListener(this);

      setBackground (Color.black);
      setSize (APPLET_WIDTH, APPLET_HEIGHT);
   }

   //-----------------------------------------------------------------
   //  Draws all of the dots stored in the Vector.
   //-----------------------------------------------------------------
   public void paint (Graphics page)
   {
      page.setColor (Color.green);

      // Retrieve an iterator for the vector of points
      Iterator pointIterator = pointList.iterator();

      while (pointIterator.hasNext())
      {
         Point drawPoint = (Point) pointIterator.next();
         page.fillOval (drawPoint.x - RADIUS, drawPoint.y - RADIUS,
                        RADIUS * 2, RADIUS * 2);
      }

      page.drawString ("Count: " + count, 5, 15);
   }

   //-----------------------------------------------------------------
   //  Adds the current point to the list of points and redraws the
   //  applet whenever the mouse is pressed.
   //-----------------------------------------------------------------
   public void mousePressed (MouseEvent event)
   {
      pointList.addElement (event.getPoint());
      count++;
      repaint();
   }

   //-----------------------------------------------------------------
   //  Provide empty definitions for unused event methods.
   //-----------------------------------------------------------------
   public void mouseClicked (MouseEvent event) {}
   public void mouseReleased (MouseEvent event) {}
   public void mouseEntered (MouseEvent event) {}
   public void mouseExited (MouseEvent event) {}
}
