JavaPackage, JavaClass, JavaObject, JavaArray, and JavaMethod
and arrays and to invoke Java methods. In Java, the
following two subsections summarize these two halves of
The JavaClass, JavaObject, JavaArray, and
JavaMethod objects allow transparent communication between
all the tricky behind-the-scenes work.
reads and writes Java values are illustrated in Figure 19.2 and Figure 19.3.
JavaObject objects. JavaObjects behave differently than
In particular, JavaObjects are converted to numeric, Boolean
You can use the JavaPackage objects referred to
by the Window properties Packages,
java, sun, and
netscape to obtain a JavaClass object for
any of the standard classes built in to Navigator. The
JavaClass object allows you to read and write static
properties and invoke static methods of a class.
You can use the new operator
on a JavaClass object to create a new Java object and a
JavaObject to read and write instance fields and invoke
You can use the
getClass() function to obtain a
JavaClass object corresponding to the Java class of a
simply by working with the predefined classes. But this
technique is limited--no significant user interaction
with a "scripted" Java program is possible.
You can also use the
document.applets array and the
JavaObject objects it contains to interact with applets.
Manipulating the fields and methods of a custom-written
applet allows a richer set of possibilities than simply
scripting with the basic Java classes.
You can use the
document.embeds array and the
JavaObjects it contains to interact with the plug-ins that
are displaying embedded data in the document. You can
control plug-ins through vendor-specific Java APIs.
class. It handles data conversion and all the
behind-the-scenes work to allow Java code to communicate
The data conversions performed when Java reads and writes
Figure 19.5 and
The getMember() and
getSlot() methods of a JSObject allow
The setMember() and
setSlot() methods allow Java to set the
The call() method of a JSObject allows
The eval() method of a JSObject allows
easier to use than the other JSObject methods.
An applet that uses the JSObject class must
import it with an import statement. To
compile the applet, the CLASSPATH
environment variable must be set to include the Java classes
supplied by Netscape.
embedded in an HTML document with an
<APPLET> tag that includes the