COMP204-08B Assignment 5
Due date: Monday, October 6, 5pm
What to submit:
One java file containing all you code.
Document your code well.
Use the javadoc @author tag to give your name and ID!
Specification:
Your task is to implement a simple interactive drawing application.
Your application will allow the user to draw closed multi-lines.
A single mouse click will add a new point to the current multi-line
(or start one, if there is no current one) and also add a line-segment
between the new point and the last point of the current multi-line.
A shift-click will add the "last" point to a multi-line, i.e. it will
add this point plus line-segments to the "last" and the "first" point
of the current multi-line, thus closing it.
You should also monitor the mouse and also draw a line between the
current mouse position and the last point of the current multi-line
(if there is one multi-line which is currently being constructed).
In addition to the drawing panel we also need three buttons:
- Reset button: will completely clear the current drawing.
- Undo button: will undo the last point/line-segment, provided we are currently drawing a multi-line. Otherwise it will just remove the last complete multi-line.
- Quit button: should bring up a modal quit dialog, and depending on the user action, quit or not quit.
To make things a bit more interesting, make sure that the "undo" and the
"reset" button are inactive, if the drawing panel is empty.
Assessment will be based on the following criteria:
- Functionality
- Reasonable clarity and style of programming.
- Reasonable documentation;
You are to implement this code "manually", do not use interface builders
like the one included in NetBeans.
Here are a few hints:
- You can directly draw on a JPanel
- Class Graphics (the argument of your frame's paint method) has methods to draw lines and circles, and also to clear rectangular areas, among other methods.
- You will need some lists to keep track of the completed multi-lines, as well as the multi-line which is currently being constructed.
- Class MouseEvent (the argument of your MouseListener's methods) has getX() and getY() methods among others.
- You will need a both MouseListener and MouseMotionListener functionality, see abstract class MouseAdapter.
- A MouseEvent is a kind of InputEvent, see that class description to find out about the SHIFT modifier.