Network Methods of java.applet.AppletContext

AppletContext is an interface that lets an applet manipulate the environment in which it is running. Every applet has an AppletContext field, which is a reference to an object implementing AppletContext. In some sense, this object represents the web browser or applet viewer that is running the applet. (In rare cases, mostly applets started from the command line and instantiated in the main( ) method, the AppletContext may be null.) To access the applet’s context, call the applet’s getAppletContext( ) method:

public AppletContext getAppletContext(  )

The AppletContext must provide several methods for the use of the applet, including getAudioClip( ) and getImage( ) methods; the getAudioClip( ) and getImage( ) methods of java.applet.Applet merely call the corresponding method in the applet’s AppletContext. However, there are two overloaded showDocument( ) methods in java.applet.AppletContext that are relevant to network programming and are not mirrored in java.applet.Applet. The first takes as an argument a single URL:

public void showDocument(URL url)

This method shows the document at URL url in the AppletContext’s window. It is not supported by all web browsers and applet viewers, but it is supported by Netscape, HotJava, and Internet Explorer. This method is most useful in fancy image map applets, where it is used to send the user to a new page after clicking on a hot button. For example, to send the user to the O’Reilly home page, you ...

Get Java Network Programming, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.