import java.io.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.awt.geom.*;


public class  mouseP3 extends JPanel implements MouseListener,MouseMotionListener
{
  //push and push again line draw
	int x1[],y1[],x2[],y2[];
  int n;
  Line2D l[];
  Color c;
 
 public mouseP3()
 {super();
  x1=new int[100];
  y1=new int[100];
  l=new Line2D[100];
  n=0;
  addMouseListener(this);
  addMouseMotionListener(this);
 }
 
 
 public void setLine(int x1i,int y1i,int x2i,int y2i)
 {x1[n]=x1i;y1[n]=y1i;x2[n]=x2i;y2[n]=y2i;n++;}
 

 public void paint(Graphics g)
 {
 super.paintComponent(g);
 Graphics2D g2=(Graphics2D)g;	 
 g2.setFont(new Font("Serif",Font.BOLD,24));	 
 g2.setColor(Color.blue);
 g2.setStroke(new BasicStroke(2.0f));
 for(int i=1;i<n;i++)
 {l[i]=new Line2D.Double(x1[i],y1[i],x1[i-1],y1[i-1]);
 g2.draw(l[i]);
 }	 
 }
    
//MouseListener (mouse dinleyicisi)
public void mouseClicked(MouseEvent e)
 {}

 public void mousePressed(MouseEvent e)
 {
    if(n==0) {x1[n]=e.getX();y1[n]=e.getY();System.out.println("n = "+n+" x1= "+x1[n]+"y1 = "+y1[n]);n++;}
    else { x1[n]=e.getX();y1[n]=e.getY();repaint();System.out.println("n = "+n+"x1 = "+x1[n]+"y1 = "+y1[n]);n++;}
 }   

  public void mouseReleased(MouseEvent e)
 {}

 public void mouseEntered(MouseEvent e)
 { }

 public void mouseExited(MouseEvent e)
 { }
//MouseMotionListener (mouse hareket dinleyicisi) metotlari

 public void mouseDragged(MouseEvent e)
 {}
 public void mouseMoved(MouseEvent e)
 {}
 
}
