Previous | Next | Trail Map | Writing Applets | Table of Contents

Communicating with Other Programs

An applet can communicate with other programs in three ways: This lesson discusses and gives examples of each kind of applet communication.

Sending Messages to Other Applets on the Same Page

Using the AppletContext getApplet() and getApplets() methods, and applet can get the Applet objects for other applets running on the same page. Once an applet has another's Applet object, the applet can send messages to the Applet object.

Communicating with the Browser

Various Applet and AppletContext methods provide limited communication between the applet and the browser or applet viewer it runs in. The most interesting are probably the AppletContext 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.(in the Networking trail)

Using a Server to Work Around Security Restrictions

One use of server-side applications is to get around applet security restrictions. For example, since applets can't perform file I/O but applications can, you could have an applet save state by forwarding it to a server-side application. The application could then save the state to a file on its own host. As another example, applets originating from the same host but running on different machines can talk to each other using a server-side application as an intermediary.

This section presents an example of getting applets running on different hosts to talk to each other. It uses sockets for communication between each applet and the server.

Previous | Next | Trail Map | Writing Applets | Table of Contents