6.837 Assignment 4


Introduction

The point of this assignment is for you to gain proficiency with the Java language, and inplement a simple interaction scheme which will allow both individual and networked drawing on a virtual whiteboard.


Overview


Communication Between Applets

The Draw applet provides collaborative drawing. It does this by sending a message to listening applets whenever a relevant low-level event, such as a mouse movement occur. The listening applets then invoke the appropriate event handling method on the appropriate object to cause the display to mirror the sending applet.

Since Java doesn't provide a mechanism for one applet to invoke a method on another applet's objects, we build our own mechanism out of sockets. To invoke a method, we write a message consisting of:

The methods to send these messages are in the DrawObject class, for instance DrawObject.sendMouseDown(). These methods are invoked from methods in the drawing classes as necessary; for instance, DrawLine.mouseDown() calls sendMouseDown() to inform other applets of the mouse down event. These messages are sent through the socket connection to chatServer, which echoes the messages to any listening Draw applets.

The DrawConnection class runs a separate thread that reads from the input stream to wait for incoming messages. For each message, DrawConnection

Thus DrawObject and DrawConnection provide a mechanism to marshal arguments, send a message to remote applets, unmarshal the arguments, and invoke a method on a remote object. This mechanism is provided automatically by distributed object frameworks such as CORBA but since Java doesn't yet provide such as mechanism, we must do it ourselves.


Example

The basic example draw application is currently available at http://lumina.lcs.mit.edu/Java/draw.html. Start a Netscape browser and go to this URL. When the applet comes up, you can draw, type, change modes, etc. on the virtual whiteboard.

To see the networked application, you will need to start two Netscape browsers. Go to the above URL in each. When each applet comes up, type lumina.lcs.mit.edu as the hostname in the applet's text dialog. Now, everything you do on one whiteboard will be replicated on the other. (Note that if others are connected to the lumina chatServer at the same time, you will see their drawing commands on your whitebaord as well, and they will see yours.)


Assignment Tasks

Below we describe four required tasks, and one extra credit task for this assignment.

Some style notes: we use typewriter font to denote class names (for example Draw) and affix parentheses to denote methods (for example Draw.init()). Note that capitalization is significant, so that (for example) the class DrawLine is distinct from the method Graphics.drawLine.


Initial Setup


Running the Standalone Applet (non-networked)


Running the Server and Multiple Client Applets:


Other Java Information


Turning in the Problem Set