Thursday, June 30, 2005

Java applets can communicate with each other easily !

There are 2 ways to do inter-applet communication:

  • the basic way is to use the methods getApplet(), getApplets() in java.applet.AppletContext. An AppletContext can be fetched using method java.appet.Applet.getAppletContext(). This way is only for applets on the same page.


  • the "trick" way is to use a (shared) public static reference to store the reference to this Applet object instance, then other applet can simply access this applet through this reference. This way is only for applets with the same codebase (codebase attribute in APPLET tag).


ref: An alternative way for applet-to-applet communication