Table of Contents |
An applet can communicate with other programs in three ways:This lesson discusses and gives examples of each kind of applet communication.
- By invoking public methods of other applets on the same page (subject to security restrictions).
- By using the API defined in the
java.applet
package, which lets it communicate in a limited way with the browser or applet viewer that contains it.- By using the API defined in the
java.net
package to communicate over the network with other programs. The other programs must be running on the host that the applet originated from.Sending Messages to Other Applets on the Same Page
Using theAppletContext getApplet
andgetApplets
methods, an applet can get theApplet
objects for other applets running on the same page. Once an applet has another'sApplet
object, the applet can send messages to it.Communicating with the Browser
VariousApplet
andAppletContext
methods provide limited communication between the applet and the browser or applet viewer it runs in. The most interesting are probably theAppletContext showDocument
methods, which let an applet tell its browser which URL to display.Working with a Server-Side Application
Applets can use networking features just as any Java program can, with the restriction that all communication must be with the host that delivered the applet to its current host. This section presents an applet version of the example from Writing a Datagram Client and Server.Also in this section is an example of how to use a server-side application to get around applet security restrictions. In the example, applets originating from the same host but running on different machines talk to each other using a server-side application as an intermediary.
Table of Contents |