CSE 341 -- Programming Languages

Winter 2000

Department of Computer Science and Engineering, University of Washington

Steve Tanimoto (instructor) and Jeremy Baer (teaching assistant).

Assignment J2

Version 1.03 of February 3.  Subject to change.

Java In-depth

Due date and time: Wednesday, February 16, 2000 at 10:30. A milestone report is due on Monday, February 8 by 5:00 PM.   (Submit your assignment electronically by filling out an online submission form.). 

Title: Java -- An Object-Oriented Drawing Program

Purposes:  To deepen your understanding of object-oriented design, to gain more familiarity with graphics and the AWT in java, to learn the basics of working with images in Java, and to get some practice designing a user interface.

Instructions:  Using the applet you wrote for assignment J1 as a base, write an object-oriented drawing program in Java that supports the following types of objects: Rectangles, Ovals, Rounded Rectangles, Text Boxes, and Images.  For all these object types, the user should not only be able to create them at any location on the screen, but once an object has been created, be able to move it, resize it, change its color, and delete it.  Additionally, for Text Boxes, the user should be able to edit the textual content.  The user should also be able to start over by clearing all the objects from the page.  The program should support at least one level of Undo.  When creating an Image object, users should at least be given a choice between a number of preselected images.  You are not required to implement the same user interface as is used in the sample program for this assignment -- in fact, it employs a fairly rudimentary interface which could do with a lot of improvement.  Please feel free to design your own interface with an emphasis on making the functionality of the program as easy for the user to access as possible.

By the way, you are welcome to base this assignment on your implementation from assignment J1, or you may use the sample implementation of J1 as a base, if you prefer. When I created the sample executable for this assignment, I based it directly on the sample executable for J1. You are welcome to do either and no points will be deducted for starting with the sample J1 code -- just please make a note of it in your documentation.

Here are some sample applets which you may find useful to look at:
Sample solution to assignment J1
Applet which demonstrates loading and displaying an Image
Applet which demonstrates the use of dialog boxes

In addition, to help you with creating Text Boxes, I have provided a utility class called TextUtils to display a String of text within a Rectangular area.  It will automatically do word-wrap, and will justify the text either left, right, or center.  You simply give it a Graphics object to draw on, the String to draw, the Rectangle to draw it in, the justification, and the Font to use.  Please note the copyright information contained in the comment at the top of the class.
Here is the code: TextUtils.java
Here is a sample applet which demonstrates its use

Optional enhancements:  After you have completed the required functionality as described above, you may wish to add more features to your program.  Successful implementation of additional features will be given a small amount of extra credit.  Here are some suggestions for additional features: (1) support basic "edit menu" functions (cut, copy, paste), (2) add support for more object types, such as lines and user-defined polygons, (3) add offscreen image buffering to get rid of redraw flicker when performing an operation like moving an object around on the screen, (4) add support for changing the layering of objects on the page (bring-to-front, send-to-back, shuffle-higher, shuffle-lower), (5) allow the user to choose whether a Rectangle, Oval, or Rounded Rectangle object is filled or not, (6) allow the user to modify the font, size, style, and justification of text boxes,  (7) add the ability to save and load documents (details and code regarding how to do this are available here, courtesy of Brad Fitzpatrick), (8) add a bit-mapped image editor to allow users to modify the image displayed by an Image Object.

Here is an executable for a sample solution.

Programming style:  Comment your method definitions clearly, using the style given in the first sample Java program.