/* Expanding Square Example Program This program starts out with a small sold square centered in the graphics window and instructions to click inthe window. On each click, the square gets bigger, but remains centered. If the mouse leaves the window the square goes back to it's original size and the text says "Start again!" in large, bold, italic letters, going back to the original text when the mouse re-eners the window. The program will take into account a resizing of the window by the user and start the squares at the center of the new window. */ import objectdraw.*; import java.awt.*; public class ExpandingSquare extends FrameWindowController { private static final int INITIAL_SIDE_LENGTH = 10; private static final int SQUARE_SIDE_INCREMENT = 20; private FilledRect square; public void begin() { // create the small black square in the center of the canvas square = new FilledRect(canvas.getWidth()/2 - INITIAL_SIDE_LENGTH/2, canvas.getHeight()/2 - INITIAL_SIDE_LENGTH/2, INITIAL_SIDE_LENGTH, INITIAL_SIDE_LENGTH, canvas); } public void onMousePress (Location point) { // increases the size of the square by SQUARE_SIDE_INCREMENT and keeps it centered square.setHeight(square.getHeight() + SQUARE_SIDE_INCREMENT); square.setWidth(square.getWidth() + SQUARE_SIDE_INCREMENT); square.move(-SQUARE_SIDE_INCREMENT/2, -SQUARE_SIDE_INCREMENT/2); } }