import objectdraw.*; import java.awt.*; /** * Creates a colored quilt on the screen. */ public class QuiltEvents extends FrameWindowController { private static final int WINDOW_SIZE = 500; private static final int NUM_QUILT_ROWS = 3; private static final int NUM_QUILT_COLS = 4; private Quilt quilt; // used to select a quilt square private FilledRect firstSquareSelected; // resize the window and make the quilt public void begin() { resize(WINDOW_SIZE, WINDOW_SIZE); quilt = new Quilt(NUM_QUILT_ROWS, NUM_QUILT_COLS, canvas); } // if the user presses on a quilt square location, get a reference // to that square public void onMousePress(Location point) { firstSquareSelected = quilt.squareSelected(point); } // if a square was selected has been selected on the mouse press, // and a square is now selected on the mouse release, change the // color of the second square to that of the first public void onMouseRelease(Location point) { FilledRect secondSquareSelected = quilt.squareSelected(point); if (firstSquareSelected != null && secondSquareSelected != null) { secondSquareSelected.setColor(firstSquareSelected.getColor()); } } }