Applet Context
Home ] Up ] Introduction to Applets ] A Simple Applet ] HTML Tags for Applets ] The Applet Life Cycle ] Multimedia and URLs ] [ Applet Context ] Converting Applications to Applets ]

 

 

An applet runs inside a browser or applet viewer.

An applet running within a browser can ask the browser to do things for it:

  • Fetch an audio clip
  • Show a short message in the status line
  • Show a different web page

The browser can perform these requests or ignore them.

  • To communicate with the browser, an applet calls the java.applet.Applet.getAppletContext() method, which returns an object that implements an interface of type java.applet.AppletContext.
  • Think of AppletContext as a communication path between the applet and the browser.
  • AppletContext provides the following methods:
    Method Description
    void showStatus(String message)
    Shows the message in the status line of the browser
    Enumeration getApplets()
    Returns an enumeration of all the applets in the same context (same web page)
    Applet getApplet(String name)
    Returns the applet in the current context with the specified name (null if none exists)
    void showDocument(URL url)
    Shows a new web page in the browser, displacing the current page.
    void showDocument(URL url, String target)
    Shows a new web page in the browser, specifying the target frame
    ("_self", "_parent", "_top", "_blank", or <frame-name>)
    Image getImage(URL url)
    Returns an image object that encapsulates the image specified by the URL
    AudioClip getAudioClip(URL url)
    Returns an AudioClip object that encapsulates the sound file specified by the URL.
 

This page was last modified on 02 October, 2007