A Design Pattern for Inter-Applet Communications
Joseph Cozad
Network-based applications today are becoming increasingly complex, using Web browsers to tie together different technologies like HTML, JavaScript, CGIs, Java, and frames. Sometimes these applications call for more than one Java applet to function. When working with projects that use these applications, developers inevitably ask themselves, "How can I make two or more applets talk to each other effectively?" In some situations, especially if the applets exist in two separately loaded Web pages, the solution to this problem can seem challenging at best.
Inter-applet communication presents several considerations: In what context are applets located? Are the applets within the same HTML document or distributed across several frames or browser windows? Should the applets maintain references to all the other applets in the application? How do the applets recognize what other applets are available? This article will offer three approaches to solving the inter-applet communication question. It will also examine applets within the context of the same HTML document, distributed across several frames, and distributed across several windows. I'll look at an all Java-based implementation method and a Java/Java
Script implementation method, and the considerations involved when applying each method to a particular context.
The Basics
As an example, I'll use two simple applets. One is responsible for accepting some text from the user and sending that text to the other applet for display.