// "Exer2b.java" - Exercise on Classes
//
// Modify this program to simultaneously slides three happy faces from the
// left side of the screen to the right side.  When the happy faces reach
// the right side of the screen, have them "bounce" and start moving left
// until they reach the left side of the screen.  Have them "bounce" a
// second time of the left hand side of the screen.
// Assume the radius of the happy face is 50.  Use applet's getSize ()
// to determine the applet's height and width.

// Modified September 16, 2007
// Philip P

import java.applet.*;
import java.awt.*;

public class Exer2b extends Applet
{
	// Use constant radius declared here since the "radius"
	// in the HappyFaceClass is not static
	//static final int defaultRadius = HappyFaceClass.radius;
	static final int defaultRadius = 50;
	
    public void paint (Graphics g)
    {
		HappyFaceClass face1, face2, face3;
		int width = getSize ().width;
		int height = getSize ().height;
		
		int xPosition = defaultRadius;
		
		// Show three happy faces at the starting x-position (edge of applet)
		face1 = new HappyFaceClass (xPosition, 100);
		face1.show (g);          // Show the happy face
		face2 = new HappyFaceClass (xPosition, 200);
		face2.show (g);          // Show the happy face
		face3 = new HappyFaceClass (xPosition, 300);
		face3.show (g);          // Show the happy face
		
		// Why only twice? Why not just keep bouncing??? ^_^
		// Edit: Wait - I remember - it makes the applet un-exitable ; /
		for (int i = 0; i < 5; i++)
		{
			// Move the happy faces to the other side
			while (xPosition < (this.getWidth() - defaultRadius)) {
				xPosition++;
				face1.move(xPosition, face1.y, g, this.getBackground());
				face2.move(xPosition, face2.y, g, this.getBackground());
				face3.move(xPosition, face3.y, g, this.getBackground());
			}
			
			// Move the happy faces to the starting side
			while (xPosition > defaultRadius) {
				xPosition--;
				face1.move(xPosition, face1.y, g, this.getBackground());
				face2.move(xPosition, face2.y, g, this.getBackground());
				face3.move(xPosition, face3.y, g, this.getBackground());
			}
		} // bouncing for loop
    } // paint method
} // Exer2b class
