Interaction with the Browser and the Web

An applet can interact with the browser and the Web through several methods of the Applet class. Commonly used methods are:

public URL getDocumentBase()
returns the URL of the document containing the applet. This is useful for changing the behavior of an applet depending on the document that contains it.

public Image getImage(URL url, String name)
returns an Image object that can be painted on the screen. The name of the image is relative to the url. This method returns immediately. The actual loading of the object is done when the applet attempts to draw the image on the screen (or off-screen).

public AudioClip getAudioClip(URL url, String name)
returns an AudioClip object. This method returns immediately. The actual loading of the data is done when the applet attempts to play the audio clip.

public void play(URL url, String name)
loads and plays an audio clip. (easier than with getAudioClip)

public String getParameter(String name)
returns the value of an input parameter. This was used in the "better" hello world applet.

public void resize(int width, int height)
requests a larger (or smaller) window. The browser may refuse a resize request.
Through the getAppletContext() method an applet gets access to other useful methods, including:
public void showDocument(URL url)
requests that the browser show the indicated Web page instead of the page containing the applet.

public void showDocument(URL url, String target)
requests that the browser show the indicated Web page. The target determines the frame to use. ("_self", "_parent", "_top", "_blank" or a new named window).

public Applet getApplet(String name)
This method returns the Applet with the given name (given using the HTML NAME attribute). Applets can call each other's public methods.