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

public class test4gruppoA extends JPanel
{
	int x = 0, y = 0;
	Palla[] pallette;
	
	public test4gruppoA()
	{
		pallette = new Palla[6];
		for (int k = 0; k < pallette.length; k++)
			pallette[k] = new Palla(x+k*50+25, 25, 50);
		
		addMouseMotionListener(new MouseMotionAdapter() { public void mouseMoved(MouseEvent e){
			x = e.getX();
			y = e.getY();

			for (int k = 0; k < pallette.length; k++)
			{
				if (pallette[k].dentro(e.getX(), e.getY())) pallette[k].isOver = true;
				else pallette[k].isOver = false;
			}
			repaint();
			}});
	}
	
	public void paint(Graphics g)
	{
		super.paintComponent(g);
		g.setColor(Color.black);
		for (int k = 0; k < pallette.length; k++)
			pallette[k].mostra(g);
		g.setColor(Color.red);
		g.fillOval(x-10, y-10, 20,20);
	}
	
	public static void main(String[] a)
	{
		JFrame f = new JFrame();
		f.setTitle("Test 4");
		f.setSize(310,80);
		f.add(new test4gruppoA());
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.setVisible(true);
	}
}

class Palla
{
	int x, y, dim, dimOver;
	boolean isOver = false;
	public Palla(int x, int y, int dim)
	{
		this.x = x;
		this.y = y;
		this.dim = dim;
		this.dimOver = dim-(int)(dim*0.3);
	}
	public void mostra(Graphics g)
	{
		if (isOver)
		{
			g.drawOval(x-dim/2, y-dim/2, dim, dim);
			g.fillOval(x-dimOver/2, y-dimOver/2, dimOver, dimOver);
		}
		else 
			g.fillOval(x-dim/2, y-dim/2, dim, dim);
	}
	public boolean dentro(int cx, int cy)
	{
		if (cx > x-dim/2 && cx < x+dim/2 && cy > y-dim/2 && cy < y+dim/2)
			return true;
		else
			return false;
	}
}
