On This Page
Overview
In this assignment you create a drawing program. You will:
- Explore the use of different Swing components in an application
- Detect mouse events and translate the event into coordinates for drawing shapes
- Reuse code you developed in an earlier assignment.
Background Information
For this assignment, you will need to use GUI components to select shapes and colors. Some of the components you can use are:
If you decide to get more creative, you can look in the big list: How to Make/Use...
You will also need to handle mouse events. Java provides two interfaces for mouse events: MouseListener and MouseMotionListener. The textbook has a discussion of mouse event handling in section 11.13. In addition, the Java Tutorial has a tutorial on How to Write a Mouse Listener.
^ top
Operation
- When run, the program presents the user with a blank drawing palette like;

Note that this is only one example of a possible GUI. You can design the GUI anyway you like, as long as it is a good user interface and meets the specifications. If you do something unusual, like popup menus, please describe how to operate your program in the README.txt file.
- The user adds a shape to the screen by dragging the mouse across the screen.

The programs draws the selected shape using the mouse drag to set the size of the shape.
- The user can draw as many shapes as they like, up to some reasonable limit.

- When the Clear button is pressed, the palette is cleared and the user can start over.
- The console displays the coordinates of each object it draws in a format like the following:
MyLine: x1 = 2, y1 = 3, x2 = 489, y2 = 355
MyLine: x1 = 3, y1 = 354, x2 = 489, y2 = 3
MyOval: x1 = 3, y1 = 3, width = 485, height = 351
MyOval: x1 = 74, y1 = 57, width = 339, height = 244
MyOval: x1 = 128, y1 = 95, width = 235, height = 169
MyOval: x1 = 166, y1 = 123, width = 160, height = 114
MyFilledOval: x1 = 190, y1 = 141, width = 113, height = 79
MyFilledRect: x1 = 215, y1 = 156, width = 62, height = 48
MyFilledOval: x1 = 154, y1 = 16, width = 167, height = 104
MyFilledOval: x1 = 353, y1 = 111, width = 107, height = 112
MyFilledOval: x1 = 308, y1 = 254, width = 141, height = 73
MyFilledOval: x1 = 46, y1 = 127, width = 107, height = 81
MyRect: x1 = 89, y1 = 57, width = 318, height = 241
You can see how the program runs by downloading PaintApp.jar and running the PaintApp program from the command line like this:
>java -cp PaintApp.jar PaintApp
^ top
Specifications
- Using your
MyShape inheritance hierarchy that you developed earlier, create an application that lets a user paint a picture using different shapes.
- You are not allowed to change any existing code in your
MyShape inheritance hierarchy, except to correct errors and add new shapes. This is so you can see the extensibility of a polymorphic design.
- Store the shapes drawn in an array so that resizing windows will not erase the drawing.
- The user must be able to select with GUI controls:
- A shape to draw (such as a line, rectangle, or oval),
- The color of the shape
- Whether or not the shape is filled
- Use the mouse to control the size of the shape drawn.
To do this, you will need to capture MouseEvents like MousePressed and MouseReleased. To see how to capture a MouseEvent, see section 11.13 of the required textbook.
- Provide a
JButton to clear the drawing area and erase all the shapes in the array.
^ top
Extra Credit
The following are worth extra credit points:
- Use an anonymous inner class to implement at least one of the event handlers. (1 point)
- Add code to allow the user to add any number of shapes by expanding the shapes array when needed. (1 point).
- Create an undo feature that lets the user delete the previous shape entered. (1 point)
- Add an animation feature that lets the user cycle through all the exisitng shapes in the array. (1 point)
- Use your imagination and code something creative. (0 to 2 points)
Make certain that your README.txt file lists any extra credit attempted.
^ top
Grading Criteria
The instructor will evaluate your assignment using the following criteria. Each criteria represents a specific achievement of your assignment and has a scoring guide. The scoring guide explains the possible scores you can receive.
Some scoring guides have a list of indicators. These indicators are a sign of meeting, or a symptom of not meeting, the specific criterion. Note that a single indicator may not always be reliable or appropriate in a given context. However, as a group, they show the condition of meeting the criterion.
For information on grading policies, including interpretation of scores, see the course information page.
Program Compilation
- 4: Source code compiles with no errors or warnings
- 0: Does not compile
Functionality
- 10: Demonstrates mastery of the assignment
- Has extra features or demonstrates techniques beyond the assignment
- Applies concepts from the lessons appropriately
- Meets all specifications (see above) with particularly elegant solutions
- Runs to completion with no abnormal error conditions
- Generates correct output given correct input
- Behaves in a reasonable way in response to incorrect data
- 8: Has all the functionality expected of the assignment
- Demonstrates many techniques from the lesson
- Meets all specifications (see above)
- Implementation seems more complicated than necessary.
- May have one minor error
- 6: Has most of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Meets all but one of the specifications (see above)
- Implementation seems excessively complicated.
- May have 2-3 minor errors
- 4: Has some of the functionality expected of the assignment
- Demonstrates some techniques from the lesson
- Meets at least 1/2 of the specifications (see above)
- Implementation seems excessively complicated.
- May have more than 3 minor errors
- 2: Serious functional problems but shows some effort and understanding
- Meets less than 1/2 of the of the specifications (see above)
- Has a major error or many minor errors
- Implementation seems very convoluted
- Demonstrates few techniques from the lesson
- 0: Does not execute
Program Style
- 4: Code is well-documented
- 3: Code has minor documentation errors
- Has 1 documentation error
- 2: Code has some documentation errors
- Has 2-3 documentation errors
- 1: Code has many documentation errors
- Has more than 3 documentation errors
- 0: No apparent attempt to document code
README.txt File
- 2: README.txt file submitted with specified information included
- 1: README.txt submitted but some information was not included
- 0: No README.txt submitted
Maximum Score: 20, plus extra credit
^ top
What to Turn In
Submit your assignment following the instructions for homework. Include the following items for grading:
README.txt file
- All of your source code (i.e.
.java files)
- Any other source code needed to make your program function
You must submit all the files needed to make your assignment function properly. Do not assume that the instructors has any files. Your assignment must work as submitted.
^ top
Home
| WebCT
| Announcements
| Schedule
| Room Policies
| Course Info
Help
| FAQ's
| HowTo's
| Links
Last Updated: April 23 2005 @17:57:04
|