Java and Inter-Applet Communication
by Andrew Meckler


Listing One
import java.applet.*;
import java.util.*;
public class CommManager
{
    private static Hashtable applets = new Hashtable();
    public static Applet getApplet(String s)
    {
        return (Applet)applets.get(s);
    }
    public static boolean regApplet(String s, Applet a)
    {
        if (a != null) {
            applets.put(s, a);
        return true;
        }
        else
            return false;
    }
    public static boolean unregApplet(String s)
    {
        if (applets.containsKey(s)) {
            applets.remove(s);
            return true;
        }
        else
            return false;
    }
}

Listing Two
public void start()
{
    CommManager.regApplet("Applet1", this);
}

Listing Three
public boolean action(Event event, Object obj)
{               
    if ("Send Message to Applet 3".equals(obj)) {
        Applet refApplet3 = CommManager.getApplet("Applet3");
        ((Applet3)refApplet3).ReceiveText(SendTextEdit.getText());
    }
} 

Listing Four
public void stop()
{
    CommManager.unregApplet("Applet3");
}


