import objectdraw.*; import java.awt.*; public class NestedSquaresIterEvents extends FrameWindowController { private static final double UPPER_LEFT_X = 10; private static final double UPPER_LEFT_Y = 10; private static final double SIDE_SIZE = 300; private NestedSquaresIter mySquares; private Location lastPoint; private boolean grabbed = false; public void begin() { mySquares = new NestedSquaresIter(UPPER_LEFT_X, UPPER_LEFT_Y, SIDE_SIZE, canvas); } public void onMousePress(Location point) { mySquares.centerOnPoint(point); if (mySquares.contains(point)) { grabbed = true; lastPoint = point; } } public void onMouseRelease(Location point) { grabbed = false; } public void onMouseDrag(Location point) { if (grabbed) { mySquares.move(point.getX() - lastPoint.getX(), point.getY() - lastPoint.getY()); lastPoint = point; } } }