Computer Science 252
Problem Solving with Java
Fall 2013, The College of Saint Rose
NestedSquaresLoop Demo
A working demo of NestedSquaresLoop will appear below. Click inside the applet to interact with it.
NestedSquaresLoop BlueJ Project
Click here to download a BlueJ project for NestedSquaresLoop.
NestedSquaresLoop Source Code
The Java source code for NestedSquaresLoop is below. Click on a file name to download it.
import objectdraw.*; import java.awt.*; /* * Example NestedSquaresLoop: a simple iterative loop to * * Jim Teresco, The College of Saint Rose, CSC 252, Fall 2013 * * $Id: NestedSquaresLoop.java 2227 2013-10-24 03:37:54Z terescoj $ */ public class NestedSquaresLoop { private static final int SIZE_CHANGE = 4; public NestedSquaresLoop(double x, double y, int size, DrawingCanvas c) { while (size > 0) { new FramedRect(x, y, size, size, c); x += SIZE_CHANGE/2; y += SIZE_CHANGE/2; size -= SIZE_CHANGE; } } }
import objectdraw.*; import java.awt.*; /* * Example NestedSquaresLoop: draw some nested squares objects * when the mouse is pressed * * Jim Teresco, The College of Saint Rose, CSC 252, Fall 2013 * * $Id: DrawNestedSquares.java 2227 2013-10-24 03:37:54Z terescoj $ */ public class DrawNestedSquares extends WindowController { public void onMousePress(Location point) { new NestedSquaresLoop(point.getX(), point.getY(), 100, canvas); } }