import javax.swing.JFrame;  // basic window
import java.awt.*;  // colors and graphics

public class Bouncer extends JFrame
{

// public variables
int width=400, height=400, ballX=0, ballY=0, diameter=50, counter=0;

// constructor
public Bouncer()
{
setLocation( 50, 50 );
setSize( width, height );
setDefaultCloseOperation( EXIT_ON_CLOSE );
setVisible( true );

// change ballX and ballY, repaint
for( int a=1; a<=1000; a=a+1 )
   {
	counter = counter + 1;
   ballX = ballX + 1;
	ballY = ballY + 2; 

	if (counter > 180)
	   {
	   ballY = ballY - 3;  // net effect is ballY - 2
	   }
	if (counter > 380)
	   {
		ballX = ballX - 4;
		}	

	delay( 200 );
	repaint();
   } // end for
	
} // end constructor

// drawing
public void paint( Graphics g )
{
g.setColor( Color.white );
g.fillRect( 0, 0, width, height );

g.setColor( Color.red );
g.fillOval( ballX, ballY, diameter, diameter );
}

// main
public static void main( String args [] )
{
Bouncer app = new Bouncer();
}

// support methods
public void delay( int delaySteps )
{
for( int b=0; b<=delaySteps; b=b+1)
   {
   System.out.print(".");
   }
}

} // end class
