Full circle – the applet is here to stay?

  • Post category:Java

For those who have been following my blogs, or heard my ‘One application to rule them all’ talk, know that I’ve been hanging a lot of my spare time experiments on my hour registration applet. It has served me well for over a decade, but the fact that browsers no longer support applets forced me to make decisions on how to maintain that functionality.

The simplest approach would have been to convert the applet into a stand alone application. Not that big of a hassle; login screen, connect to the HTTP back end, and off you go. But I decided to try and write a JavaFX application instead, with a login screen connecting to that back end, which is able to run on multiple platforms. Just for the sake of experience.

But the discoveries made during this effort have uncovered some interesting gems, and I wanted to share this one: CheerpJ. It runs any old fashion applet in a browser via Javascript, without any changes to the code!

cheerpj

Initially I was highly sceptical, and I still am a bit, because it seems like quite a stretch. But the people at LeaningTech were very no-nonsense, and quickly -after fixing some normal issues with any beta level product- my original applet was chucking along nicely!

In the least invasive setup CheerpJ installs as a plugin in Chrome. You then see a small icon in the toolbar, and when a page is loaded with an applet in it, the icon turns orange and a popup can be opened.

cheerpj-plugin

Clicking on ‘Run Applets’ will start the magic. Now, because this is a Java applet, CheerpJ has to on-the-fly convert all jar files to JS files and that will take a while. In the javascript console you will see a lot of ‘missing …js’ errors, which the CheerpJ plugin is picking up.

These missing JS files can be uploaded before hand, which removes the need for the plugin to convert them, and naturally will greatly improve startup time.

cheerpj-startup

Having these files available before hand is something I’ll try later, but for now a bit of patience suffices and… Tadaaa!

cheerpj-applet

Mind you, this is NOT Java running! Even though it looks almost identical! This really is Javascript executing my JAR files. And I had not made a single change. It pretty much blew me away.

To prove this, I’ll open the debug view.

cheerpj-html

Yes, that is a HTML canvas being used to render that applet.

Amazing!

Since the applet, after 10 years of tuning, is much more refined than the new JavaFX application, I must say that this is a very very appealing solution. Of course there are still some questions. For example: how is the integration with the browser; I have not attempted to open one of the reports yet, but I will soon. But these are minor compared to the feat of running an applet as Javascript.

And it even performs well.

I’m still not quite getting my mind around it. Kudo’s to the CheerpJ team.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.