Java Applets: Utility Methods

The Applet class provides a set of useful methods (in addition to the five methods init(), start(), paint(), stop(), and destroy()) that can be used for different purposes. A brief description of commonly used methods is given here:

isActive() — Returns true if the applet is active, false otherwise. An applet becomes active just before the start() method is called and becomes inactive just before the stop() method is called.

resize (int width, int height)— Sets the size of the applet’s window with the specified width and height

resize(Dimension new) — Sets the size of the applet with the specified dimension

showStatus (String message) — Displays the specified message in the status bar of the browser’s window

getDocumentBase() — Returns the URL of the document containing this applet getCodeBase() — Returns the URL of the base directory from which this applet was loaded getParameter (String param) — Returns the value of the specified parameter passed to this applet

getParameterInfo() — Returns a two-dimensional array of strings that contains information about the parameters that this applet understands.

getAppletContext() — Returns a java.applet.AppletContext object that represents applet’s context, which allows us to query, and affects applet’s environment.

getAppletInfo() — Returns information about the applet as a string getImage(URL url) — Returns an Image object from the specified URL of the image

getImage(URL base, String name) — Returns an Image object from the specified base URL and relative name of the image

newAudioClip(URL) — Creates an AudioClip object specified by the URL getAudioClip(URL) — Returns an AudioClip object specified by the absolute URL argument

getAudioClip(URL, String) — Returns an AudioClip object specified by the absolute base URL and relative name arguments

play(URL) — Plays an audio clip specified by the absolute URL

play (URL, String) — Plays an audio clip specified by the absolute base URL and a relative name

Source: Uttam Kumar Roy (2015), Advanced Java programming, Oxford University Press.

Leave a Reply

Your email address will not be published. Required fields are marked *