CSCI 136: Assignment 3 -- The artist!

Due 3/3/97

Your assignment is to add a new subclass, RectGrid, of Canvas, which supports a two-dimensional grid of rectangles. The rectangles can be assigned colors, can compute which rectangle a point is contained in, and can display the grid. Because RectGrid is a subclass of Canvas, it can be drawn on and can be inserted as a component of other objects (like an Applet).

A skeleton for the subclass is available on-line and a print-out is attached. The purpose of each method should be clear from the pre- and post-conditions. I have left the choice of instance variables entirely up to you. I expect you to find an efficient way to determine whether a click is in one of the cells of the grid and returning the one it is in. This operation should take a constant amount of time, no matter how large the grid is. I.e., do it by calculation rather than search for full credit!

I have provided a program, TestGrid, and a supplementary class, CurrentColorCanvas, designed to test your class. They can be found in the assignment folder along with the skeleton subclass. A demo version of this program which behaves the way that your program should appears here:



Notice that the column of buttons on the right side act as a palette of colors which can be used to select the current color, while the rectangles in the grid are painted the current color when clicked upon. Remember to include your name as the first comment in your file. When you are done, create a folder whose name includes yours and make sure it includes the "project", all of the classes used in the program, and all of the compiled code in "Java classes". Please drag the folder into the dropoff folder of the CS136 folder on Courses to turn it in.