import java.awt.*;
import java.awt.event.*;

public class Examp3 extends Frame
{
  private int diam;
  private int x, y;
  private int xsize, ysize;
  private int xinc, yinc;
  public Examp3()
  {
    this.diam = 40;
    this.xinc = 1;
    this.yinc = 2;
    this.x = 50;
    this.y = 50;
    this.xsize = 360;
    this.ysize = 360;
    this.setLayout(null);
    this.setSize(this.xsize, this.ysize);
    this.setTitle("First example");
    this.setResizable(false);
    this.setBackground(Color.gray);
    this.setVisible(true);
  }

  public void go() throws InterruptedException
  {
    while(true)
    {
      Thread.sleep(12);
      repaint();
    }
  }
    
 
  public void paint(Graphics g)
  {
    g.setColor(Color.blue);
    if(this.x + this.diam/2 > this.xsize)
      xinc = -1;
    if(this.x - this.diam/2 < 0)
      xinc = 1;
    if(this.y + this.diam/2 > this.ysize)
      yinc = -2;
    if(this.y - this.diam/2 < 0)
      yinc = 2;
    this.x += this.xinc;
    this.y += this.yinc;
    g.fillOval(this.x - this.diam/2, this.y - this.diam/2, 
      this.diam, this.diam); 
  }
 

  public static void main(String args[]) throws InterruptedException
  {
    Examp3 e = new Examp3();
    e.go();
  }
}