B629: Languages for Programming the Web
Project 2: A drawing editor applet


On CS machines, the directory
contains java sources implementing a drawing editor applet, parts of which were discussed in class. (The same files can be found in the project handouts directory.) Copy this directory to your own filespace.

Running the AppletViewer

Applets can be viewed in two ways: with the appletviewer application provided as part of the Java Development Kit or using a web browser. To run appletviewer, type
    appletviewer Draw.html
(note that the argument is an html file, not a class file).

When you recompile your program and want to see how it behaves, it is not enough to use the "Reload" command of the appletviewer: this reloads the HTML page, but not the applet code (the class files). You have to exit and restart the appletviewer. The Makefile provided in the handout does this for you each time the program is compiled.`

Running HotJava

To view the drawing editor applet with HotJava, type:
    hotjava file:[full path name of Draw.html] 
for example:
    hotjava file:/u/pierce/pub/629/handouts/project2/Draw.html
Note: HotJava is the only browser that currently supports Java version 1.1. This applet will not work with current versions of Netscape or Internet Explorer.


As in the first project, your assignment consists of several small extensions to the existing code, finishing with a more serious design task (not for extra credit this time!). Since you'll be working in groups on this one, the expected standards of coolness will be higher.
  1. Add a new "color button" to the column on the left-hand side of the applet, allowing shapes to be drawn in purple.
  2. Add a whole new column of color buttons, adjacent to the first one. Fill it with several more colors. You'll need to use a new Panel for the column of buttons and another Panel to group the two panels of color buttons together for inclusion in the top-level applet.
  3. Change the file Draw.html so that it creates and displays three separate drawing editors of different sizes.
  4. Add a method main to the drawing applet so that it can be used as either an applet or a stand-alone application. When it is run as an application, make it display a Quit button that causes it to exit.
  5. Extend the Shape interface so that it extends the Serializable interface (i.e., so that every shape is serializable).
  6. Add buttons Save and Load. Save should write the current drawing to the file whose name has been typed in the command line area at the bottom of the applet. Similarly, Load should load a saved drawing from the file whose name is in the command line.
  7. Design and implement a mechanism for selecting a shape in the drawing by clicking on it with the right-hand mouse button. Add a Delete button that removes the selected shape from the drawing. [This is the serious part of the assignment!]

Extra credit:

  1. Extend the Shape interface so that shapes can be drawn either solid or (as they are currently) as outlines. Make the middle mouse button add solid shapes, while the left mouse button keeps its current behavior of adding outline shapes.
  2. Extend the selection mechanism to allow several objects to be selected at once (for example, by sweeping the mouse through an area containing them).
  3. Additional extensions of your choice.


As before, a finished project consists of the following files:
  1. A file README (or, if you prefer, README.html) containing a brief, but well polished, design document. Concentrate on describing your design and implementation of the selection mechanism, since this is the interesting part of the assignment.
  2. Java source files (including documentation)
  3. A Makefile such that typing
      make demo
    will recompile files as necessary and then show your program doing something.


  1. You'll need somewhere to look up details of the 1.1 AWT interfaces. There are many books covering this material; it can also be found in the online tutorial. (But be careful: some parts of the tutorial refer to the old 1.0.2 version of the AWT. There is a special section on new 1.1 features.)
  2. The online API guide is up to date for the 1.1 interfaces.
  3. Material on the Serializable interface can be found in the on-line documentation for JDK 1.1.

Submission Procedure

Same as before.

Due date

The project is due at the beginning of class on Monday, September 21st.

B629: Languages for Programming the Web
Benjamin Pierce (pierce@cs.indiana.edu)