X

Sundararajan's Weblog

  • Java
    August 30, 2006

Scriptlets

Guest Author

Just added scriptlet application to http://scripting.dev.java.net

A Scriptlet is a Java applet written in JavaScript. With scriptlets, developers
use a predefined applet class (called com.sun.scriptlet.Scriptlet)
and define an applet param which identifies a JavaScript. The JavaScript
code can define one or more script functions to "override"
applet's methods such as start, stop, init, destroy or paint.

By just defining paint function, scriptlet becomes equivalent to the new canvas tag.
But unlike canvas tag, scriptlet functions can access the entire
JDK API. The current applet object is exposed as first argument
to scriptlet's functions. For example, using this applet argument, scriptlets can play audio (by calling play method). With just the knowledge of JavaScript and Java API, very nice applets can be written.

Using

Java-to-Javascript Communication
between Java to
browser's built-in JavaScript engine, a global variable named window
is defined. This window variable can be used by scriptlet scripts to access browser's script objects. For example, window.location.href returns the URL of the currently visited web page. Similarly window.document can be used to get the DOM document object of the current HTML page. Few simple scriptlets are in the applications/scriptlet/src/scriptlets directory of the scripting project.

Join the discussion

Comments ( 1 )
  • Andres Almiray Wednesday, August 30, 2006
    This looks really amazing. What I like most is that bidirectional communication between Java and the browser is so transparent. No more JSObject and JSException in the middle of my applet code, just plain old "JavaScript".
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.