This section includes the following topics:
With scripting you have the capability to call applet methods from within an HTML page. In addition to invoking methods, you can use scripts to:
You need to include the following in your applet's HTML page:
These tags are explained in the following sections.
The ID parameter is the symbolic name of the applet. Once you establish a symbolic name for an applet through the ID parameter, you can reuse this name later in the scripts to refer to this applet.
For example, suppose you have an applet called Fractal. You add the ID parameter to the OBJECT tag and set ID to the symbolic name of the applet. You might set the tag as follows:
Now, you can use the name Fractal within scripts to refer to the Fractal applet.ID="Fractal"
Using the same Fractal applet example, your HTML page would begin with a FORM tag, followed by an OBJECT tag, that together might look as follows:
<form name="Form1"> <OBJECT ID="Fractal" WIDTH=500 HEIGHT=120 CLASSID="CLSID:8AD9C840-044E-11d1-B3E9-00805F499D93" <PARAM NAME="code" value="CLSFractal.class"> <PARAM NAME="codebase" value="1.0.2"> <PARAM NAME="level" value="5"> ... </OBJECT>
The HTML page defines components that are intended to invoke actions triggered by the user. You use the INPUT tag to define these components. You specify the TYPE of the component, such as button, its NAME, and VALUE. To have the button or other component actually invoke the intended action, you need to add tags that specify:
For example, suppose your HTML page creates a button that, when clicked, starts a particular animation sequence. Your HTML tag creates the button and gives that button a name and a value (label).
To do this you want to add two tags. One tag indicates that on a
certain action, such as
onclick, a corresponding
script method should be called. You might have the tag
onClick="method name". The method name is a script method
within the same HTML page.
Thus, you might have the following in your HTML page:
For example, the same HTML page might have the following SCRIPT tag:
In this example, the SCRIPT tag begins by specifying
function statement, which starts the
definition of a scripting method. The
statement supplies a label or name for the scripting method,
calling it startJSFractal. This name must match the method
name given for the input component's action parameter.
For this example, both the onClick parameter and the
function statement specify the identical scripting method.
The scripting method startJSFractal merely calls the
actual method, startFractal(), implemented in the applet
code. It qualifies the method name by using the document form name
, then the applet name (
the method name itself, as follows:
Copyright © 1993, 2011, Oracle and/or its affiliates. All rights reserved.