CPSC 170 Spring 2003
Program 2: Drawing Shapes
Due Friday, February 28

Overview

Write a program that allows the user to create colorful shapes within a grid by clicking with the mouse. Your program should present the user with a blank (white) window, which is logically divided into a grid. When the user clicks on the window, a blue triangle should be drawn in the square of the grid where the user clicked. When the user clicks on that area of the grid again, a red circle should replace the blue triangle. When the user clicks there again, that square of the grid should become plain white again. See the demo. (Save it to your directory, do "tar xzf demo.tgz", cd to the demo directory, and do "java Shapes".)

Program Organization

These are some of the important components that your program should contain. Note that this is just a description; you probably should not write the program in this order. Read the Getting Started section below for advice on where to begin.

Getting Started

To get started, you might want to write just the Shape and Square classes, plus the constructor and paintComponent methods for the ShapePanel class. (Of course, you'll need the driver too.) In the constructor, fill the grid array with white squares and see if this displays correctly (the window should be all white). When this works, add the ShapeListener class and make it replace the square that you click on with a square of a different color. When this works, try adding the shapes, thinking about how to get each to draw correctly, and then rotate them. Voila!