Outline
On CS machines, the directory
/u/pierce/pub/629/handouts/project2
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.
Assignment
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.
- Add a new "color button" to the column on the left-hand side of
the applet, allowing shapes to be drawn in purple.
- 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.
- Change the file Draw.html so that it creates and
displays three separate drawing editors of different sizes.
- 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.
- Extend the Shape interface so that it extends the
Serializable interface (i.e., so that every shape is
serializable).
- 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.
- 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:
- 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.
- Extend the selection mechanism to allow several objects to be
selected at once (for example, by sweeping the mouse through an
area containing them).
- Additional extensions of your choice.
Deliverables
As before, a finished project consists of the following files:
- 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.
- Java source files (including documentation)
- A
Makefile
such that typing
make demo
will recompile files as necessary and then show your program
doing something.
Documentation
- 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.)
- The online API guide is up to date for the 1.1 interfaces.
- 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)