// See the URL // http://www.cns.uni.edu/~jacobson/061/applets/ver3Boxball/CAST.html import java.awt.*; import objectdraw.*; public class CAST0 extends WindowController { private FilledRect r; private Text t; public void begin() { r = new FilledRect(50, 50, 400, 400, canvas); r.setColor( Color.yellow ); t = new Text("Great exam practice - while loops" + " - onMouseRelease() event - Colors, FilledRects", 20, 5, canvas); t.setBold(); } public void onMouseRelease(Location point) { if ( r.contains(point) ) { // Initialize: Prepare for the FIRST rectangle... double x = point.getX(); double y = point.getY(); int i = 1; int red = 255; while (i <= 5) { // Create the current rectangle... Color theColor = new Color(red, 0, 0); new FilledRect(x, y, 50, 10, canvas).setColor(theColor); // Prepare for the NEXT rectangle - 2nd, 3rd, 4th, or 5th red -= 50; x += 5; y += 10; i++; // when i == 6 the loop is done... } } } }