Availability: |
| |||
JavaScript syntax: | N | myJavaObject = new java.lang.Object | ||
N | myJavaObject = 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.
When JavaObject objects are used in JavaScript expressions, even though internally they may contain a value that could be represented by a JavaScript primitive type, they do not behave like that JavaScript primitive type. Instead, they behave according to the rules of the Java object type that contains the value. This can sometimes cause scripts to behave in unexpected ways, for example you might get a concatenation instead of a numeric addition. You should also explicitly test for values and not make assumptions that a null or undefined value is returned.
The JavaObject in Netscape is notably unforgiving. Many other JavaScript objects will yield the value undefined if you ask for a property that does not exist. A JavaObject will generate a run-time error and so you cannot easily test for the existence of an unknown property.
Some objects also support a strangly named function that is referred to by an enumerable but apparently unnamed property. It is exposed when you enumerate the properties in a for( ... in ... ) loop and output their names with a document.write(). A property appears in the list that seems to have no name. Checking the property names with the typeof operator reports this as a string so it's not an undefined name. OK, so let's measure its length. The suspect property reports a length of 6 in the example I was testing but it is still invisible. Here's where we try hunches and use our debugging instincts. Wrap the property name in the escape() function. That should tell us what weird characters are there. Voila. It reports that the name is now %3CInit%3E. So the name is the word Init wrapped in < and > characters, which explains why we couldn't see it. The web browser thought it was a tag and didn't recognise it so it was hidden.
The second piece of example code shows how the properties were enumerated and how to display the hidden property name.
// 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>
Property | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
description | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
filename | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
length | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
name | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Method | JavaScript | JScript | N | IE | Opera | NES | ECMA | DOM | CSS | HTML | Notes |
---|---|---|---|---|---|---|---|---|---|---|---|
booleanValue() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | - |
destroy() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
disable() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
doubleValue() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
enable() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getAppletContext() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getAppletInfo() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getBackground() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getClass() | 1.2 ![]() | ![]() | 4.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getCodeBase() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getDocumentBase() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getLocale() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getParameter() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getParameterInfo() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
getToolkit() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
hide() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
init() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
isActive() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
isEnabled() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
isShowing() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
isValid() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
isVisible() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
minimumSize() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
refresh() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
start() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
stop() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
toString() | 1.1 ![]() | ![]() | 3.0 ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
Prev | Home | Next |
JavaMethod object | Up | JavaObject.booleanValue() |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |