import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.geom.Ellipse2D;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import javax.swing.JComponent;

public class MouseDotComponent extends JComponent implements MouseListener {
   

   private ArrayList<Point2D.Double> points = new ArrayList<Point2D.Double>();
   
   // TODO: You will ned to add additional instance variable(s)
     
   private static final int RADIUS = 5; // Radius of each dot.
   
   // These MouseListerner methods do not need to do anything in this program
   public void mouseClicked(MouseEvent arg0) { }
   public void mouseEntered(MouseEvent e)    { }
   public void mouseExited(MouseEvent e)     { }
   public void mouseReleased(MouseEvent e)   { }

   public void mousePressed(MouseEvent e) {
      Point2D.Double p = new Point2D.Double(e.getX(), e.getY());
      points.add(p);
      // TODO: You will need to add additional code here:

      this.repaint();
   }

   // Auxiliary method called by PaintComponent to draw a dot.
   private static void drawDot(Graphics2D g2, Point2D.Double center){
      g2.fill(new Ellipse2D.Double(center.x - RADIUS, center.y - RADIUS, 2*RADIUS, 2*RADIUS)); 
   }
    
   @Override 
   public void paintComponent(Graphics g) {
      Graphics2D g2 = (Graphics2D)g;
      int num = this.points.size();
      // Draw the points, and lines between them.
      for (int i = 0; i < num; i++){
            Point2D.Double p = this.points.get(i);
            drawDot(g2, p); 
            if (i > 0) {
               Point2D.Double p2 = points.get(i-1);
               g2.draw(new Line2D.Double(p.x, p.y, p2.x, p2.y ));
            }
      }
      // TODO: You will need to add additional code here:
      
    }
}