Whiteboard Applet
One of the examples that seems like an
obvious candidate for use as an applet is our whiteboard example from Chapter 10. Currently, support for RMI within web
browsers is scarce, so let’s concentrate on a message-passing
version of the whiteboard, instead of the RMI-based version shown in
Example 10.3. The message-passing version is very
similar, but is based on the MessageCollaborator
and MessageMediator
classes from that chapter.
This version, which we called the
MsgWhiteboardUser
, is shown in Example 1.1. Since the differences between this and the
RMI-based WhiteboardUser
are minor, we
won’t go into details about the code here.
package dcj.examples.Collaborative; import dcj.util.Collaborative.*; import java.awt.event.*; import java.awt.*; import java.util.Hashtable; import java.util.Properties; import java.io.IOException; import java.util.Vector; class Msg { public Object data; public String tag; public Msg(Object o, String t) { data = o; tag = t; } } class CommHelper extends Thread { Collaborator collaborator; static Vector msgs = new Vector(); public CommHelper(Collaborator c) { collaborator = c; } public static void addMsg(Object o, String t) { synchronized (msgs) { msgs.addElement(new Msg(o, t)); } } public void run() { while (true) { try { Msg m = null; synchronized (msgs) { m = (Msg)msgs.elementAt(0); msgs.removeElementAt(0); } collaborator.broadcast(m.tag, m.data); } catch (Exception e) {} } } } public class ...
Get Java Distributed Computing now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.