import java.awt.*;
import java.awt.event.*;
import java.util.Random;

public class Balls extends Frame
{
  private int diameter;
  private int width, height;
  private int x, y, delx,dely;
  private Random ran;

  public Balls(int w, int h)
  {
    this.ran = new Random();
    this.diameter = 30;
    this.width = w;
    this.height = h;
    this.x = diameter;
    this.y = diameter;
    this.delx = 2;
    this.dely = 1;
    this.setSize(w, h);
    this.setBackground(Color.YELLOW);
    this.setVisible(true);
    //repaint();
  }

  public void paint(Graphics g)
  {
    g.setColor(Color.RED);
    if(x > this.width - diameter || x < 0)
    {
      delx = -delx;
    }
    if(y > this.width - diameter || y < 0)
    {
      dely = -dely;
    }
    x += delx + ran.nextInt(7) - 3;
    y += dely + ran.nextInt(7) - 3;
    g.fillOval(x, y, diameter, diameter);
    try
    {
      Thread.sleep(15);
    }
    catch (Exception e)
    {
    }
    repaint();
  }

  public static void main(String args[])
  {
    Balls b = new Balls(400, 400);
  }
}
   
  

