import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.*;

public class lez20070410 extends JFrame
{
	public static void main (String[] args)
	{
		lez20070410 f = new lez20070410();
		f.setVisible(true);
	}
	
	public lez20070410()
	{
		setTitle("Prova");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(400,400);
		Pannello p = new Pannello();
		add(p);
	}
}

class Pannello extends JPanel implements MouseMotionListener
{
	ArrayList<Punto> coordinate;
	int x=0, y=0;
	Pannello() 
	{
		coordinate = new ArrayList<Punto>();
		addMouseMotionListener(this);
	}
	
	public void paint(Graphics g)
	{
		super.paintComponent(g);
		for (int h = 1; h < coordinate.size(); h++)
		{
			Punto pp = coordinate.get(h-1);
			Punto p = coordinate.get(h);
			g.drawLine(pp.x,pp.y,p.x,p.y);
		}
	}
	
	public void mouseMoved(MouseEvent e) {}
	public void mouseDragged(MouseEvent e) 
	{
		coordinate.add(new Punto(e.getX(), e.getY()));
		repaint();
	}
}

class Punto
{
	int x, y;
	Punto(int x, int y)
	{
		this.x = x;
		this.y = y;
	}
}
