« July 2009
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 
       
Today
XML

Blog::Navigation

GetJava Download Button
Get the Source
Personal Blog

Blog::Referers

Today's Page Hits: 481

Powered by Roller Weblogger.
« Multiple language... | Main | Extra bytes at the... »
20060830 Wednesday August 30, 2006

Scriptlets

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.



( Aug 30 2006, 09:07:34 PM IST ) Permalink Comments [1] del.icio.us | furl | simpy | slashdot | technorati | digg

Comments:

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".

Posted by Andres Almiray on August 30, 2006 at 10:59 PM IST #

Post a Comment:

Comments are closed for this entry.
Copyright (C) 2005, A. Sundararajan's Weblog