One problem we have run into with Java is trying to send commands
and data between two or more currently executing applets. While it
is theoretically possible to do this in a single document by
retrieving the document's list of applets through the
java.applet.AppletContext.getApplets()
method, there
appears to be no easy way to get a handle on applets executing in
different frames or windows.
The ClassRegistry was created to address this need. It works by defining a class with static methods for registering objects and sending messages to them. All objects using the same ClassRegistry class share this information, so that commands can be sent to objects existing in different applet contexts.
We have available a simple demo showing the registry in action.
To use the ClassRegistry in your own program, you need to do two things:
Create a class that implements a
ClassConnection
interface. Instances of this
class may then be registered as an arbitrary name with the
ClassRegistry by calling its addClass()
method.
In another class, call the registry's
doCommand()
method to send a command to the objects
in the registry, using the same name as above.
The demo available on this page uses two simple applets that implement this functionality.
To use the ClassRegistry in your own code, just retrieve the source code as a compressed (18K) or gzipped (10K) tar file; this includes compiled binaries, the demo HTML files, and source code with comments explaining how to use the registry.
ClassRegistry
The actual class that keeps track of registered objects. The class should never be instantiated; instead, it is used by calling the static methods of the class, to register objects with it and send messages to the currently registered objects.
Because the class's methods and data are static, they are shared between all objects that use the class: thus an object in one applet or document can "see" the objects registered by another.
Note that, for this to work, your objects must all be accessing the same class: i.e., they must use the registry at the same URL. The practical implication of this is that the applets that wish to communcate with each should be stored in the same directory on your server, along with the actually ClassRegistry class.
RegistryButton
An applet implementing a simple button that sends a message to a ClassRegistry every time it is pressed by the user. There are four parameters used to control its behavior:
RegistryDemo
Implements a simple applet for the demo. All it does is create a TextArea and register itself with a ClassRegistry, then it displays information about the commands sent to it by the registry.
ClassConnection
The interface that must be implemented by any object that wishes to register itself with the ClassRegistry.
Last modified: Mon Jul 22 17:55:39 PDT 1996