import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Random;
public class Star extends JFrame implements ActionListener
{
private int width = 400, height = 400;
private int xPoints[] = { 55, 67, 109, 73, 83, 55, 27, 37, 1, 43 };
private int yPoints[] = { 0, 36, 36, 54, 96, 72, 96, 54, 36, 36 };
private Polygon star1 = new Polygon(xPoints, yPoints, 10);
private Polygon star2 = new Polygon(xPoints, yPoints, 10);
private Timer timer;
private int count = 0; 
private Random myGen = new Random();

public Star()
    {	     	
    setSize( width, height );
    setDefaultCloseOperation( EXIT_ON_CLOSE );

    star1.translate(0, 50);
    star2.translate(0, 50);
    timer = new Timer( 50, this);
    timer.start();
   
    setVisible( true );   
 
    } // end main

public void paint (Graphics g)
   {
   g.setColor( Color.white );
   g.fillRect( 0,0, width, height);

   g.setColor( Color.red );
   g.fillPolygon( star1 );
   g.setColor( Color.blue); 
   g.fillPolygon( star2 );
   }

public void actionPerformed (ActionEvent e )
   {

   int xMove = myGen.nextInt( 11 );
   int yMove = myGen.nextInt( 11 );
   star1.translate( xMove-5, yMove-5 );

   xMove = myGen.nextInt( 11 );
   yMove = myGen.nextInt( 11 );
   star2.translate( xMove-5, yMove-5 );

   repaint();
   }
} // end class
