JavaObject object (Object/Navigator)

A JavaScript data type that encapsulates a Java object. These are generally going to be members of the Java component class

Availability:

JavaScript - 1.1
Netscape - 3.0
JavaScript syntax:NmyJavaObject = new java.lang.Object
NmyJavaObject = document.applets[anIndex];
Object properties:description, filename, length, name
Object methods:booleanValue(), destroy(), disable(), doubleValue(), enable(), getAppletContext(), getAppletInfo(), getBackground(), getClass(), getCodeBase(), getDocumentBase(), getLocale(), getParameter(), getParameterInfo(), getToolkit(), hide(), init(), isActive(), isEnabled(), isShowing(), isValid(), isVisible(), minimumSize(), refresh(), start(), stop(), toString()

To make any serious use of this object, you need to know a little Java - at least enough to be able to be familiar with the class structures and creating and modifying objects. If you know how to make your own applets then that is probably sufficient to get started with.

The public properties of the Java Class of which the JavaObject is an instance are presented as properties of the JavaObject object. A JavaObject also inherits the properties from the java.lang.Object Class and any other classes which are in its superclass hierarchy. These are generally available by means of accessor methods so they will likely be listed as methods rather than properties.

The public methods of the Java Class of which the JavaObject is an instance are presented as methods of the JavaObject object. A JavaObject also inherits the methods from the java.lang.Object Class and any other classes which are in its superclass heirarchy.

The only properties and methods this object has, correspond to the public properties and methods of the Java object that it represents. You can enumerate the properties in a loop to inspect the interface to the object from your own scripts; like this:

for(myProp in myJavaObject)

{

document.write(myProp);

document.write("<BR>");

}

There may be some properties that are not revealed by this and you may need to resort to some Java documentation for further details. Properties and methods for the objects in Java are documented in more depth in Java Programmer's Reference, written by Grant Palmer and published by Wrox Press, which covers JDK 1.3 extensively.

To operate on the JavaObject objects, you really need to know something about the Java objects they encapsulate. There are many standard classes and some that may have been custom written for your project.

Beware that the object may report accessors that don't actually have any purpose in the object you have enumerated.

For properties and methods that apply to the Applet object in the context of an MSIE browser, examine the Applet object topic and its related items. This is documented separately because it does not support the same Java - JavaScript bridging mechanism and provides a mutually exclusive set of properties for communication with the Applet object.

Although JavaScript exposes a great many of the properties of an Applet by means of Accessor Methods, it is probably not safe to call the more destructive of them from JavaScript. However, you may usefully want to use the various enquiry methods to find out about the Applet and its internals. Many of these Accessor Methods yield other objects whose properties can also be inspected by using the same enumeration techniques.

Having examined some applets and other miscellanous Java objects, a summary list of the accessor methods is presented at the head of this topic.

Some fragments of example code are given here and a couple of important methods are described in adjacent topics. Documenting all the interfaces to an Applet or Java object is so dependent on the object that you should refer to the Applet documentation and source and a Java reference manual for details of the internals of Java code.

Warnings:

Example code:

   // Output some text to the Java console
   java.lang.System.out.println("Some text message");
   // Create a JavaScript object that encapsulates a Java Object
   var myJavaDateObject = new Packages.java.util.Date;
   --------------------------------------------------------------
   <!-- Debugging hidden property values -->
   <HTML>
   <HEAD>
   </HEAD>
   <BODY>
   <TABLE BORDER=1>
   <SCRIPT>
   // Create a JavaScript object that encapsulates a Java Class
   var myJavaDateClass = new Packages.java.util.Date;
   // Now enumerate its properties
   var myIndex = 0;
   for(myProp in myJavaDateClass)
   {
   document.write("<TR><TD>");
   document.write(myIndex);
   document.write("</TD><TD>");
   document.write(myProp);
   document.write("</TD><TD>");
   document.write(typeof(myProp));
   document.write("</TD><TD>");
   document.write(myProp.length);
   document.write("</TD><TD>");
   document.write(escape(myProp));
   document.write("</TD></TR>");
   
   myIndex++;
   }
   </SCRIPT>
   </TABLE>
   </BODY>
   </HTML>

See also:Applet object, Document.applets[], Document.embeds[], EmbedArray object, Java to JavaScript values, java.lang.Object, JavaObject.booleanValue(), JavaScript to Java values, LiveConnect, Packages.java, Packages.netscape, Window.Packages

PropertyJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
description1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
filename1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
length1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
name1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning

MethodJavaScriptJScriptNIEOperaNESECMADOMCSSHTMLNotes
booleanValue()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/a-
destroy()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
disable()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
doubleValue()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
enable()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getAppletContext()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getAppletInfo()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getBackground()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getClass()1.2 1.2 n/a4.0 4.0 n/a n/a n/a n/a n/a n/a n/aWarning
getCodeBase()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getDocumentBase()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getLocale()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getParameter()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getParameterInfo()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
getToolkit()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
hide()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
init()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
isActive()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
isEnabled()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
isShowing()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
isValid()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
isVisible()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
minimumSize()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
refresh()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
start()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
stop()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning
toString()1.1 1.1 n/a3.0 3.0 n/a n/a n/a n/a n/a n/a n/aWarning