SE-1021 Software Development 2
Lab 8: Drawing Program - Part 1

Outcomes

bulletDesign and implement a Graphical User Interface (GUI) using Java Swing classes
bulletimplement inheritance and polymorphism on classes that extend an abstract class
bulletimplement handling of events generated by a graphical user interface
bulletimplement exception handling in an application to react to error conditions
bulletimplement file I/O read and write files

Assignment

In this multi-part assignment, you will create a Java application with which a user can

bulletdraw a variety of graphical shapes (lines, ellipses, and rectangles)
bulletprovide a way of selecting colors for the created shapes
bulletsave the drawn shapes to a file
bulletreload the file containing the previously saved shapes

An example UI is shown below, but you may extend and customize this UI, provided that you receive approval from your instructor before submitting your assignment. Minimally, you must implement a menus, radio buttons, and a way to display the current mouse cursor coordinates (as shown). You may add additional graphics components (buttons, toolbars, checkboxes, etc) if you obtain approval.

In this lab (Part 1), you will implement only those aspects of the application's functionality that allow a user to:

bulletselect a shape to be drawn with via a radio button
bulletcreate a shape (in a fixed color of your choice) by moving the mouse to a starting point, pressing the mouse button, moving the mouse to an ending point, and releasing the mouse button. Every time this is done, the selected type of shape is created and added to the collection of shapes.
bulleterase the collection of shapes via the File/New menu item
bulletexit the program via the File/Exit menu item

The application does not have to support the selection of shape colors, background color, save the drawn shapes to a file, nor load a file of previously-saved shapes. That functionality will be added in the next assignment.

Application Structure

The UML class diagram below illustrates the overall structure of the entire application. You will have to create the classes shown in blue; the others already exist in a partially-completed state.

Assignment details for Part 1

In this assignment, you will add UI creation and event-handling logic to a partially-completed version of this application.

Project Setup

bulletFirst create the Lab8 project. Download this lab8.zip file; then follow these steps to import it :
  1. With the Lab8 project selected in the Package Explorer select File -> Import...
  2. From the Import dialog select General -> Archive File and click Next
  3. Click the first Browse button to and select the lab8.zip file you downloaded
  4. When you have selected the lab8.zip file click Open and then Finish to complete the import. You will see a folder named src in your project; right-click this folder, and select Build Path/Use this source folder from the context menu. Once part of the build path, you'll see a single package: edu.msoe.se1021.drawing.YOURNAME.
bulletRename the edu.msoe.se1021.drawing.YOURNAME to match your MSOE username (see steps below).
  1. Select the package name in the package explorer
  2. Right-click and select Refactor -> Rename from the context menu
  3. Enter the new name and click OK

The lab8.zip file includes the following classes:

bulletDrawingProgramApp.java - A main class that is also the UI, which also contains several private inner classes: MenuHandler, RadioButtonHandler, MouseEventHandler, and DrawingPanel.
bulletAbstractShape.java

You must add the following classes:

bulletEllipse.java
bulletRectangle.java
bulletLine.java

Implementation

Follow the TODO comments in these classes; they instruct you what you need to add to provide the necessary functionality.

Note: Remember to comment your code. All classes and all methods must be commented using Javadoc comments.

Lab Submission (due date in Blackboard)

  1. Demonstrate your Drawing Program to your instructor. If you can't do this by the end of class, you must demonstrate it sometime during Office Hours before the following lab. You will not receive a grade until you provide this demonstration. Demonstrations after the due date will be considered a late submission.
     
  2. Upload all files (Ellipse.java, Rectangle.java, Line.java, DrawingProgramApp.java, and AbstractShape.java) through Blackboard (assignment "Lab 8: Drawing Program - Part 1"). Be sure to keep copies of all your files, in case something gets lost. You may zip the files if you wish.

Your grade will be based on the following criteria:

bulletMeeting requirements; your program must compile and run, and produce well-formed, explicit error messages. If you have trouble, you must come to see me. If you don't and you submit a program that does not compile or produce detailed meaningful results will receive a grade of no higher than 50, even after reworking your program.
 
bulletTechnical quality of your program. Technical quality consists of formatting, commenting, and following coding style guidelines.
 
bulletSpelling and grammar.
 
bulletTimeliness of submission as stated in the course policies.