Java Reference
In-Depth Information
Because the methods of the AppletContext class are clearly browser-centric, and
because of the relationship that traditional Java applets have with a web browser, the
methods are not as powerful as the context provided to MIDlets and Xlets. One interest-
ing deficiency of the AppletContext class when compared with the MIDlet and Xlet
contexts is the inability of an applet to request its own termination via the context;
instead, an applet that wants to terminate its own execution must perform a showDocument
request to a URL different than that of the document containing the applet.
Communicating Between Applets
As you might surmise from the AppletContext 's getApplets method, more than one applet
can be running at once, and more than one applet can share the same applet context.
This lets multiple applets sharing the same applet perform interapplet communication,
as each of the applets sharing a single context can learn of each other's existence and
invoke each other's methods. For multiple applets that obtain information from the
applet server, you might perform interapplet communication to pipeline requests so that
only one applet needs to perform the network activity, for example. In order for applets
to communicate with each other, the applets must originate from the same server (and,
depending on the implementation, the same directory on the same server) and run in the
same context—typically, in the same window of the browser or on the same screen.
For one applet to find another, the searching applet must know the sought applet's
name. How you specify this depends on how the target device loads applets; if the target
hardware uses a web browser as its container for applets, you'll specify the name of an
applet using either the <APPLET> tag or a <PARAM> tag when you specify the source of an
applet. For example, you might write the code shown in Listing 10-4.
Listing 10-4. Specifying the Name of the Applet
<APPLET CODEBASE="applets/" CODE="HelloWorld.class"
WIDTH=200
HEIGHT=200
NAME="hello"/>
Listing 10-4 uses the NAME attribute of the APPLET tag, but you can also use the more
extensible PARAM attribute of the APPLET tag, as you see in Listing 10-5.
Listing 10-5. Another Way to Specify an Applet Name
<APPLET CODEBASE="applets/" CODE="HelloWorld.class"
WIDTH=200
HEIGHT=200>
<PARAM NAME="name" VALUE="hello"/>
</APPLET>
 
Search WWH ::




Custom Search