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

public class stimoloAdva extends JFrame
{
	static Color coloreDiPartenza = null;
	public stimoloAdva()
	{
		setSize(500,500);
		setTitle("Griglia");
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setLayout(new GridLayout(4,4));
		for (int k = 0; k < 16; k++)
			add(new Rettangolo());
		setVisible(true);
	}
	
	public static void main(String[] a){stimoloAdva f = new stimoloAdva();}
}

class Rettangolo extends JPanel
{
	public Rettangolo()
	{
		setBackground(new Color( (int)(Math.random()*255),(int)(Math.random()*255),(int)(Math.random()*255) ) );
		addMouseListener( new MouseAdapter(){
			public void mousePressed(MouseEvent e) {
				stimoloAdva.coloreDiPartenza = getBackground();
				System.out.println(this);
			}
			public void mouseReleased(MouseEvent e) {
				System.out.println(this);
			}
			} );
	}
}



