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:

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:

  1. Functionality
  2. Reasonable clarity and style of programming.
  3. 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:

  1. You can directly draw on a JPanel
  2. 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.
  3. You will need some lists to keep track of the completed multi-lines, as well as the multi-line which is currently being constructed.
  4. Class MouseEvent (the argument of your MouseListener's methods) has getX() and getY() methods among others.
  5. You will need a both MouseListener and MouseMotionListener functionality, see abstract class MouseAdapter.
  6. A MouseEvent is a kind of InputEvent, see that class description to find out about the SHIFT modifier.