Menu

Home

ub Bob Hanson
Attachments
ChiefComplaint-mini.png (51315 bytes)
EDPNG-mini.png (70744 bytes)
PatReg-mini.png (40624 bytes)
TB-mini.png (76274 bytes)

SwingJS Overview

The overall objective of SwingJS is to allow rapid porting of Java Swing Applets to JavaScript/HTML5 with a minimum of refactoring. By "rapid" we mean hours to days for adaptation and seconds for development testing and deployment.

Downloading the Applets

The applets are designed to work from the web, but you can download them and run them locally if you set up your browser for local file access. The applets can be downloaded from https://sourceforge.net/p/swingjs/code/HEAD/tree/PhET/zip/ . For non-PhET applets, just unzip swingjs.zip and navigate to the swingjs/examples directory and start index.html there. Or look in the swingjs/examples/applets directory for individual files.The PhET applets have their own swingjs/examples/phet directory for local file access in their own zip file, also in that server location.

Contributing

Are you a Java programmer? Now is the time to contribute, if you are interested! All constributions will be recognized in a forthcoming publication, and coauthor status will be given to anyone who uses this as an opportunity to contribute in a substantial way to the SwingJS project itself. Contact hansonr@stolaf.edu if you are interested in helping us on this. Al work at this point in time needs to be done within Eclipse Juno (4.2). See https://sourceforge.net/p/swingjs/wiki/SwingJS%20Conversion%20Roadmap/ for some suggestions for getting started.

Status Highlights

As of Dec, 2016, 57 applets have been converted.

Key features that work flawlessly are reflection (on-the-fly loading of classes), method overloading and overriding (methods with the same name but different signatures or positions in the class heirarchy), layout managers, event queuing and notification, threads (of a sort, somewhat restricted due to the fact that there really is only one thread in JavaScript, but this is not a major limitation), ZIP and GZIP file loading, image and zip file creation, and modular packaging (the equivalent of manifested JAR files, but in this case compiled with Google Closure Compiler).

Substantial portions of supporting packages of Java, including java.lang, java.io, java.util, javax.swing, javax.imageio, and javax.audio are in place and working smoothly. Complex Swing Applets load and run satisfatorily.

A test site has been set up at https://chemapps.stolaf.edu/swingjs/site/swingjs/examples, which at the end of 2016 had 57 working applets available for download, including a full range of Falstad applets as well as five PhET ideal gas applets.

Optimization has proven critical. Optimized performance is running at 15% to 90% of Java speeds, (with the higher speeds in the cases where animation delays are built into the Java).

Code can also be run directly in JavaScript.. The following works from the browser developer console after loading test.htm:

Clazz.loadClass();
Class.loadClass("jsjava.text.SimpleDateFormat");
// ...wait for classes to load...
x = new jsjava.text.SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
x.format(new Date);

reporting: "Sat, 4 Apr 2015 03:57:31 -0500"

The first line initializes the "Class" object and allows uncompressed class loading. The call to Class.loadClass initiates loading of the SimpleDateFormat class and all necessary classes it depends upon.

The last two lines create and use the java.text.SimpleDateFormat object.

This can all be done in one call, with an onLoaded callback:

Class.loadClass(
"jsjava.text.SimpleDateFormat",
function() {
x = new jsjava.text.SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
x.format(new Date)
}
);

History

SwingJS development started in March of 2015 and is in full development at this time. There has been huge success.

Necessary Java 1.6 code has been imported from http://hg.openjdk.java.net/jdk6.

The project derives from two successful ports of Java applets to HTML5. Both use the Java2Script (J2S) Eclipse-based compiler (see https://github.com/zhourenjian/java2script) with a customized client JavaScript library. J2S projects are developed in Java, tested in Eclipse as Java applications or applets, and then, via a few relatively involved ANT tasks, ported to JavaScript for further browser-based testing and deployment.

The Jmol Java Applet, developed by Bob Hanson, St. Olaf College, was ported to JavaScript/HTML5 in late 2012 and early 2013 and is under very active and mature development as JSmol. See http://sourceforge.net/p/jsmol.

JSmol is fully operational. It is identical in operation to its Java counterpart, including massively scriptable thread-like behavior (simultaneous molecular vibration, spinning, and user mouse-event based manipulation) and reasonable 3D visualization performance without WebGL. With 160,000+ lines of ported Java code and 600,000+ documented page views per month, JSmol serves as proof-of-concept that the Java2Script compiler/library is a serious and already successful solution to the Java-to-JavaScript problem. Since 2012, Two other Java projects, JSpecView and AstexViewer, have been ported successfully. Real-time conversion to JavaScript takes approximately 3 minutes; full packaging and deployment takes about 30 minutes.

The second project is ClientJS, developed by Udo Borkowski, abego Software et.al.. The project successfully ported several legacy Java Applet applications, mainly from the health care area, to be used as pure HTML5/JavaScript web pages. All applets are highly interactive, using table and form driven screens. The resulting HTML5/JavaScript pages use all kinds of components to provide an user experience often only known from desktop applications, including features like menu bars, tabbed register panels, combo boxes, sortable tables and many more. The Java applet version and the HTML5/JavaScript version co-exist and are created from the same source code.

But JSmol is mostly not a Swing application (With just a pop-up menu and a console). And although JSpecView and ClientJS are Swing applications, they are only minimal implementations, both using just enough "Swing-like" classes to get the job done. The goal of SwingJS is more ambitious: to provide a drop-in replacement functional Java SWING library that allows JavaScript/HTML "native" backing for all standard Swing components. A certain amount of refactoring will be necessary, of course. And there will be plenty of limitations.

Limitations

See differences.txt