Documentation Contents |
This section includes the following topics:
This chapter requires understanding the specific HTML tags required for Java Plug-in. For information about these tags, refer to Using OBJECT, EMBED, and APPLET Tags in Java Plug-in. You also should be familiar with JavaScript.
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:
<input type="button" name="Button1" value="Start" onClick="startJSFractal" language="JavaScript">
This INPUT tag creates a button, names the button "Button1", and gives it the value "Start" (the label that appears on the button). It also specifies the scripting method that will be called when a user clicks the button, and the scripting method's language. In this example, the scripting method is startJSFractal, and the scripting language is JavaScript. When the user clicks this button, the HTML page branches to the script method startJSFractal, which is written in JavaScriptscript.
For example, the same HTML page might have the following SCRIPT tag:
<SCRIPT language="JavaScript"> function startJSFractal() { document.Form1.Fractal.startFractal() } </SCRIPT>
In this example, the SCRIPT tag begins by specifying
that the scripting language is JavaScript. This is followed by the
JavaScript function
statement, which starts the
definition of a scripting method. The function
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 (OBJECT
ID
), then
the method name itself, as follows:
document.Form1.Fractal.startFractal()
Copyright © 1993, 2011, Oracle and/or its affiliates. All rights reserved. Please send comments using this Feedback page. |
Java Technology |