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

public class bouncer extends JFrame implements ActionListener
{
// these are here because they are shared by main, paint, actionPerformed.
// must be static for use in main
public static int ballX = 0;
public static int ballY = 0;
public static int diameter = 0;
public static int width = 400;
public static int height = 400;
public static int counter = 0;
public static Timer timer;  

public static void main(String[] args)
   {
	 diameter =50;
	 
	 bouncer ball = new bouncer( );
	 
    ball.setSize( width, height );
    ball.setVisible( true );
	 ball.setDefaultCloseOperation( EXIT_ON_CLOSE );
	 
    timer = new Timer( 10, ball);
    timer.start( );
    } // end main

public void paint (Graphics g)
   {
   // background (erase ball)
   g.setColor( Color.white );
   g.fillRect( 0,0, width, height);
   // ball
   g.setColor( Color.red );
   g.fillOval( ballX, ballY, diameter, diameter );
   }
   
public void actionPerformed(ActionEvent e)
    {
    ballY = ballY+2;

    ballX++;
 
    repaint( );  // call paint method
   
	 if(counter++ == 400)
       {
       timer.stop();
       }
    if(counter > 100)
      {
      ballY = ballY - 4 ; // net effect -1
      }
    }
	
} // end class

