|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Enabling LiveConnectBy default in Netscape Navigator, Java and JavaScript are enabledwhenever these languages are enabled, LiveConnect is enabled as well. To confirm that they are enabled in your copy of Navigator, choose Edit, Preferences. Then, in the Categories list, select Advanced, make sure that the Enable Java and Enable JavaScript boxes are checked, and then click OK.
The Java ConsoleNetscape Navigator has a Java Console that can be displayed by choosing Window, Java Console. Messages sent using java.lang.System.out or java.lang.System.err appear in this console. Now, because of the communication possible between JavaScript and Java using LiveConnect, messages can be sent to the Java Console from JavaScript as well. To write a message to the Java Console from JavaScript, use the println method of java.lang.System.out or java.lang.System.err, as in the following: java.lang.System.err.println(JavaScript checkpoint #1)
The Netscape PackagesNetscape Navigator includes several Java packages used to enable LiveConnect communication. The first, netscape, is used to enable communication back and forth between JavaScript and Java applets. Additionally, replacement java and sun packages are provided. These feature security improvements for LiveConnect. The following netscape packages are included:
JavaScript to Java CommunicationWith LiveConnect, JavaScript can make calls directly to Java methods. As already shown in the Java Console section, this is how JavaScript can output messages to the Java Console. To JavaScript, all Java packages and classes are properties of the packages object. Therefore, the full name of a Java object in JavaScript would be something like Packages.packageName.className.methodName.
Java applets can be controlled through JavaScript without knowing too much about the internal construction of the applet, as long as a few conditions are true. The first step is to attach a NAME attribute to the <APPLET> tag when including the Java applet in your HTML document. Then all public variables, methods, and properties of the applet are available for access to JavaScript. Any time you want to pass information into a Java applet, you might want to consider using JavaScript to do this. If you have a Java applet that implements a calendar, for example, you could create an HTML form with attached JavaScripts to enable the user to select what month should be displayed. By using JavaScript in this way, you avoid the need to give the applet itself the capability to interact with the user. Netscape shows a simple demo of controlling a Java applet by using JavaScript at http://developer.netscape.com/docs/technote/javascript/liveconnect/Fade.html. The Java applet is included in the HTML document by using the following: <APPLET CODE=Fade.class NAME=Fader WIDTH=400 HEIGHT=100> <PARAM NAME=text1 VALUE=Look at this text carefully!> <PARAM NAME=url1 VALUE=<http://www.netscape.com>> <PARAM NAME=font1 VALUE=Helvetica,PLAIN,36> </APPLET> The name Fader attached to the applet is how the Java applet is controlled. When any of the parameters entered in the form elements are changed, one of the public Java methods of this applet (setFont, setText, setUrl, setAnimateSpeed, or setBackgroundColor) is called through its onChange event.
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |