|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
For this to work, therefore, the Java methods need to be defined as public methods. When called, each method takes the parameter supplied and changes the characteristics of the applet (see Figure 23.2). As an example, the setText method is defined as a public method, as shown here: public void setText(int which,String text) { bgChange = true; thoughts.theThoughts[which] = text; thoughts.Reset(); }
Java to JavaScript CommunicationThe first step in enabling your Java applets to access JavaScript properties is to import the javascript package into your Java applet, as shown here: import netscape.javascript.* This enables the Java applet to access JavaScript properties through the JSObject class. However, the author of the HTML document must still enable access to his JavaScript by including the MAYSCRIPT attribute in the <APPLET> tag used to include the Java applet. If the Fader used in the last example needed to access JavaScript, for example, the <APPLET> tag would look like the following: <APPLET CODE=Fade.class NAME=Fader MAYSCRIPT 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> If these two conditions have been satisfied, accessing JavaScript objects or methods is a two-step process, as follows:
Similar to JavaScript to Java communication, Java to JavaScript communication can be useful when you dont want to re-create an input or output interface within your Java applet. You might create a Java applet that makes use of Javas network and Internet capabilities to access data from a database server on some other machine. Rather than using Java to display this data, you can access JavaScript objects to display it within a conventional HTML form. JavaScript and Plug-InsJavaScript can be used with the client to determine what plug-ins the client has installed and what MIME types are supported. This is done through the navigator object, through two of its properties: plugins and mimeTypes. JavaScripts can also be used to call plug-in functions.
By determining at the client whether a particular plug-in is installed or MIME-type supported, you can write scripts that generate content dynamically. If a particular plug-in is installed, the appropriate plug-in data can be displayed; otherwise, some alternative image or text can be shown.
|
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. |