Homework 5
CS202, Summer 2006

Due: Thursday, August 24

Please upload your source code files using CSNS. Note that file uploading will be disabled automatically after 11:59PM of the due date, so please turn in your work on time.


[Reading]  Read the following sections of SUN's Java Tutorial

[Problem Description] In this assignment we will implement a drawing program called CSPaint (and in case you're wondering, the name CSPaint comes from the MSPaint program, which can be found in the Accessories program folder on most Windows computers). CSPaint allows a user to draw simple shapes like line segments, ovals, and rectangles.

The GUI of CSPaint consists of three basic parts: a menu bar, a tool bar, and a drawing area. A sample of the user interface is shown in the figure below:

CSPaint

The menu bar should include the following menus:

The tool bar contains four buttons, "o", "s", "c", "u", which corresponds to Open, Save, Clear, and Undo operation, respectively. The tool bar also has a drop-down menu (implemented using JComboBox), which allows a user to choose to draw a line, an oval, or a rectangle.

Drawing a line in the drawing area starts with a mouse click, which specifies the first end point of the line. A second mouse click specifies the second end point, and completes the line. Drawing a rectangle also starts with a mouse click, which specifies one corner point of the rectangle. A second mouse click specifies the corner point diagonal to the previous corner point, and completes the drawing. Drawing an oval is similar to drawing a rectangle - two mouse clicks specify a rectangular region, and the oval enclosed in this region is drawn. Rubber-banding must be implemented for all drawings.

One of the ways to save a drawing is to transform the shapes into strings and save them in a text file. For example, a line with two end points (100, 200) and (200,300) can be saved in a file as "line 100 200 200 300". You may design your own file format, but the file names should have the .csp suffix.

When the program try to load from a file with the wrong format, a CSPaintFileFormatException should be raised. The program should not exit upon receiving such an exception; instead, print an error message and move on.

[Grading] 20% of the total credit for this assignment is reserved for proper use of inheritance, encapsulation, and particularly, polymorphism. [Extra Credit Work] There are many ways to improve upon the basic design and implemention discussed in the problem description. Here're some ideas: