import java.awt.Color;
import java.awt.Graphics;

import javax.swing.JPanel;
public class DessinAnime extends JPanel
{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private boolean clefContact = true;
	private double monAngle = 0.0;
	private Moteur monMoteur = new Moteur();
	public DessinAnime()
	{
		//repaint();
		monMoteur.start();
	}
	
	public void paint(Graphics g)
	{
		int centreX = this.getWidth() / 2,
			centreY = this.getHeight() / 2,
			rayon = this.getHeight() / 3,
			satellX1 = centreX + (int)(rayon * Math.cos(monAngle)),
			satellY1 = centreY - (int)(rayon * Math.sin(monAngle)),
			satellX2 = centreX - (int)(rayon * Math.cos(monAngle)),
			satellY2 = centreY + (int)(rayon * Math.sin(monAngle));
		g.setColor(Color.black);
		g.fillRect(centreX - rayon - 15, centreY - rayon - 15, rayon * 2 + 30, rayon * 2 + 30);
		g.setColor(Color.red);
		g.fillOval(satellX1 - 15, satellY1 - 15, 30, 30);
		g.setColor(Color.green);
		g.fillOval(satellX2 - 15, satellY2 - 15, 30, 30);
		g.setColor(Color.cyan);
		g.drawLine(satellX2, satellY2, satellX1, satellY1);
	}
	
	private class Moteur extends Thread
	{
		@Override
		public void run()
		{
			// TODO Auto-generated method stub
			
			while (clefContact)
			{
				monAngle += Math.PI / 180;
				if (monAngle > 2 * Math.PI)
				{
					monAngle -= 2 * Math.PI;
				}
				repaint();
				try
				{
					Thread.sleep(10);
				}
				catch (InterruptedException e)
				{
					e.printStackTrace();
				}
			}
		}
	}
}
