Extending JavaScript with Java
Using JavaScript to Interface with Java Applets
By Kamran Husain
Netscape Navigator 3.0 allows JavaScript applications to work and interact with Java applets. A much more powerful language than JavaScript, Java includes features such as support for sockets and graphics. However, a Java applet controls only its own space on an HTML page, not the page itself. JavaScript, on the other hand, makes it easy to create your Web pages and dictate the format and layout of a page using frames and documents. (See "Sharing Data Between Web-Page Frames Using JavaScript," by Tom Tessier, Dr. Dobb's Journal, May 1996.)
In this article, I'll show how to include applets in HTML code so that JavaScript can use them as objects, how to write applets that allow JavaScript applications to control the values of variables within applets and, finally, how to write JavaScript applications that work with Java applets.
Interfacing with Java
By manipulating a Java applet's global variables, a JavaScript program can influence its behavior. Here, we will adjust the visual display of a gauge applet. The ideas presented here can be extended to modify other aspects of a Java control using JavaScript. For example, you could get an Internet address from within a JavaScript application and then open a socket to a server from within an applet.
Combining Java applets with JavaScript code somewhat parallels Microsoft's Visual Basic code with OCXs (or the older VBXs) to put together a complex application.