Assignment 3 - Due by 11:59 pm Wednesday, March 25, 2009

Click here for submission instructions.

Develop a Java program, JSketchPad, that can be used to create drawings that are composed of triangles and ovals. None of these figures are filled. If you wish, you may start with the code (1,2) discussed in class and add functionality to it.

Your program MUST have the following functionality:

  1. (20 points) A fully menu-driven user interface, including (at a minimum) the following menu options:
  2. (20 points) Allow the user to draw triangles. The desired interaction is:
    1. User uses mouse clicks to mark vertices, and mouse drags to draw the sides of the triangle. An object corresponding to the triangle is instantiated and stored in an appropriate array, or list.
  3. (20 points) Allow the user to draw ovals using the mouse. The desired interaction is:

    1. User presses left mouse button to indicate top left corner of the rectangle that contains (is the bounding box for) the oval.
    2. User drags mouse to draw oval. The oval being drawn is visible during the drag operation.
    3. Mouse release marks the bottom right corner of the bounding rectangle. An object corresponding to the oval is instantiated and stored in an appropriate array, or list.
  4. (10 points) Minimizing the window and restoring it, or otherwise occluding the window, should not affect the drawing.

  5. (20 points) Allow the user to select one of the objects in the drawing. The desired interaction is:

    1. User chooses the Select menu option. Program enters selection mode.
    2. User clicks on the drawing. The "nearest" object is selected, and selected object turns red.
    3. You may use any reasonable algorithm to determine the "nearest" object.
  6. (20 points) Allow the user to cut a previously selected object. The object is removed from the appropriate array or list.

  7. (20 points) Allow the user to store a textual representation of a drawing in a text file. Use a JFileChooser to select a file. (See section 9.8 of your text for an example illustrating the use of a JFileChooser).The text file must follow the format detailed below to describe the objects.
    1. Rectangles are described as: T x1 y1 x2 y2 x3 y3. The x and y correspond to the coordinates of the 3 vertices of the triangle.
    2. Ovals are described as: O topLeftX topLeftY width height. The dimensions are those of the oval's bounding box.
  8. (20 points) Load a stored drawing from a file and display it. The user should then be able to edit the drawing. Use a JFileChooser to select a file.Your program should be able to load any drawing that uses the format detailed above.
  9. (20 points) Allow the user to move a currently selected object. In this mode, the selected object moves to a new location as the mouse is dragged. The movement of the object is visible during the mouse drag.
  10. (10 points) Conformance to the following coding conventions.
  11. (10 points) Code well commented. Comments should say what is being accomplished, not how it is being accomplished.