please dont rip this site

JavaScript: The Definitive Guide

Previous Chapter 21
JavaScript Reference
Next
 

JavaObject Object

Name

JavaObject Object---JavaScript representation of a Java object

Availability

Navigator 3.0

Synopsis

javaobject.field    read or write an instance field

Properties

Each JavaObject object contains properties that have the same names as the public instance fields and methods (but not the static or class fields and methods) of the Java object it represents. These properties allow you to read and write the value of public fields. The properties of a given JavaObject object obviously depend on the type of Java object it represents. You can use the for/in loop to enumerate the properties of any given JavaObject.

Description

The JavaObject object is a JavaScript representation of a Java object. The properties of a JavaObject object represent the public instance fields and public instance methods defined for the Java object. (The class or static fields and methods of the object are represented by the JavaClass object.)

The JavaObject object implements the LiveConnect functionality that allows JavaScript programs to read and write the public instance fields of a Java object, using normal JavaScript syntax. The JavaObject also provides the functionality that allows JavaScript to read the methods of a Java object, although it is the JavaMethod object that allows JavaScript to actually invoke those methods. Data conversion between JavaScript and Java representations is handled automatically by LiveConnect. See Chapter 19, LiveConnect: JavaScript and Java for full details.

Usage

Bear in mind that Java is a typed language. This means that each of the fields of an object have a specific data type, and you can only set them to values of that type. For example, the width field of a java.awt.Rectangle object is an integer field, and attempting to set it to a string will cause a JavaScript error to occur.

Example

java.awt.Rectangle is a JavaClass that represents the java.awt.Rectangle class. We can create a JavaObject that represents an instance of this class like this:

var r =index.html new java.awt.Rectangle(0,0,4,5);
And then we can read the public instance variables of this JavaObject r with code like this:

var perimeter =index.html 2*r.width + 2*r.height;
We can also set the value of public instance variables of r using JavaScript syntax:

r.width =index.html perimeter/4;
r.height = perimeter/4; 

See Also

"getClass()", "java", "JavaArray", "JavaClass", "JavaMethod", "JavaPackage", "Packages", Chapter 19, LiveConnect: JavaScript and Java


Previous Home Next
JavaMethod Book Index JavaPackage

HTML: The Definitive Guide CGI Programming JavaScript: The Definitive Guide Programming Perl WebMaster in a Nutshell

file: /Techref/language/java/script/definitive/refp_182.htm, 6KB, , updated: 2019/10/14 15:00, local time: 2024/11/20 08:28,
TOP NEW HELP FIND: 
18.191.186.12:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://massmind.org/techref/language/java/script/definitive/refp_182.htm"> [Chapter 21] Reference: JavaObject</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to massmind.org!

 

Welcome to massmind.org!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .