Project 3. CSPaint
CS202, Summer 2004
Due: Thursday, August 26
Please upload your files using the online turnin server.
Note that file uploading will be disabled automatically after 11:59PM
of the due date, so please make sure to turn in your solutions in time.
For all homework assignments and projects, failing to comply with the required
code conventions (see Review of
Language Basics, slide #7) will incur a
credit penalty up to 10% of the total credit for the assignment.
[Reading] Read the following sections of SUN's Java Tutorial
[Problem Description] In this project 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 machines). CSPaint allows a
user to draw simple shapes like line segments, ovals, and rectangles.
[GUI] 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:
The menu bar should include the following menus:
- File
- Open - opens a previously saved drawing
- Save - saves current drawing
- Exit - Exit the program
- Edit
- Clear - clears current drawing
- Undo - Remove last drawn shape
- Help
- About - displays some information about the program
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] 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.
[File Format and Exceptions] 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.
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 and Extra Credit Work] 20% of the total credit for this
assignment is reserved for proper use of inheritance, encapsulation,
and particularly, polymorphism.
- GUI components (20pt)
- Drawing (50pt)
- File I/O and exceptions (30pt)
- Extra credit work -- there are many ways to improve upon the
basic design and implemention discussed in the project description.
Here're some ideas:
- Draw polygons and polylines (30pt)
- Draw text strings (15pt)
- Choose background and drawing colors (15pt). Note that your
data structures and file format need to be changed accordingly.
- Various visual and user interface enhancements, such as image
buttons on the tool bar (15pt), and graying out the Undo button when no
shapes have been drawn (5pt).
- Anything else you want to do. Please discuss your ideas with me
first so we can decide how much extra credit should be awarded for your
work.