CPSC 124, Fall 2001
Programming Assignment 3


This is an individual programming assignment. You can get help from me and from the TA on this assignment. Otherwise, you should work on the assignment on your own. You are not permitted to look at other students' programs or to get help on the assignment from them or to help other students.

The assignment is due on Friday, November 16. If you turn it in by Wednesday, November 28, a late penalty of 20% will be deducted from the grade. Assignments will not be accepted after November 28. If you have done some work but do not have a working program, you should turn in what you have for partial credit.

You should copy your program (both source code and class file) along with all the support files that it needs to run into your cs124_homework directory. I expect to be able to find your program in this directory and run it there. You should also make a printout of your program for me.


Your assignment is to write an applet that has at least the same functionality as the applet shown at the bottom of this page. This applet uses the class MosaicCanvasX, which is an extended version of the mosaic class that was used in the previous assignment. You should read the source code for this class to find out about all the methods that it contains. You don't have to read the "insides" of the subroutines. You just need to know what subroutines are available and what they can do. Note especially the findRow() and findColumn() methods, which will make your life a whole lot easier.

In this applet, the user makes a mosaic by clicking and dragging on the mosaic grid. As the user drags the mouse, the color of a square is set according to the value selected on the scroll bar. To make things more interesting visually, there is a slight random variation in color. The scroll bar just gives a basic color, which is modified a bit at random for each square. The Fill button fills the whole mosaic with the same basic color (with some random variation). The Clear button does the obvious. The small color patch at the lower right shows the basic color that is currently selected. Its color changes as you drag the scroll bar.

For full credit, you must include at least one of two features. If you program the applet in the obvious way, then when you jiggle the mouse around inside a single square, its color will change randomly. This doesn't seem desirable. To fix this, you can keep track of the row and column of the square that you colored most recently so that you can avoid coloring the same square twice in a row. Alternatively, you can implement an Undo button using the copyColorData() and restoreColorData() methods from the MosaicCanvasX class. (Only the first of these options is illustrated in the applet shown below.)

There are other ways to improve the applet, if you want. The applet has a single scroll bar that controls the "hue" of the color. You could add another scroll bar to control the degree of randomization. You could have scroll bars to control the saturation and brightness of the color. You could make the applet draw horizontal or vertical lines of squares if the user holds down the shift key. You could let the user erase a square by right-clicking on it. You could add a Checkbox to control whether "grouting" is drawn between squares, and you could have some way of controlling the color of the grouting. You could add a way for the user to change the background color from black to another value.

You will start working on this assignment in Lab 10, which includes a "tutorial" that will get you started on the applet. There is a copy of MosaicCanvasX.java in the Lab 10 folder. The lab will show you how to use the scrollbar and how to lay out components in the applet.


David Eck, 31 October 2001