Posted by joshy
on October 3, 2004 at 10:33 AM PDT
Joshua releases a pretty Web Start countdown timer that can be customized without changing any code at all.
The commercial Applet market never really took off. Maybe because customizable libraries were eventually integrated into development tools. Maybe just because Java didn't work well in the browser until after everyone stopped caring. Whatever the reason, there simply isn't much money to be made with small commercial programs embedded into your webpage.
Still, the idea of simply customized applications still intrigues me. Many programs could be completely reconfigured by an intelligent non-programmer with the help of some config files and some bitmaps. When these thoughts collided with my recent interest in MiniApps I took the logical step and combined the two:
The Countdown Timer
Halloween Counter Webstart Link (safe)
Countdown to Christmas Webstart Link (safe)
What we have here is a single webstart program running out of the same jar files. The only difference between them is their JNLP files. The files contain configuration information says what images, colors, and fonts to use; along with the target date (10/31/2004 for example) and some layout coordinates. I can hand this counter to a non-programmer and he/she could reconfigure it completely with just a text editor. Presto: a new app formed out of the reusable components provided by Java and Webstart.
To keep it simple I have simply passed the configuration properties into the program using commandline arguments, which are then parsed into a hashtable. Here's the setup for the Halloween counter:
There are defaults for all of these values so you don't have to specify them all. In typical webfashion any external resource like images and fonts are specified using a URL. Since they are all hosted on the same site as the app itself I didn't have to request any extra permissions.
Here is the configuration for Christmas. This is the only change between the two programs. The jars remain the same.
I've turned off the transparency effect so the countdown timers can run without needing any extra permissions. The resources are loaded from the same server as well. Perhaps with some support from the javax.jnlp package I could even use relative URLs.
Once you run a couple of these your machine will really start gasping for memory. Shared JVMs is starting to become a necessity.
Icons are truly a pain with Java Web Start. You can specify more than one icon but only the first one is used. (You can use a second image as a splashpage if you set the kind to splash.) The height and width arguments are also ignored. Transparency does seem to be supported, contrary to other reports I've seen, but you can only use GIFs and JPGs. No PNGs. Ack! If you have your Windows desktop set to use large icons then webstart will scale your images down to 32x32 and then back up to 48x48. (all while doing a really bad job of it). Infinitely frustrating. There's got to be a better way to do this. I'd also like to see Frame.setIconImage() use an Icon instead of an Image. That way you could provide the right sized image for each situation. Ex: 16x16 for the taskbar, 32x32 for the tab switcher, 128x128 for the OSX Dock, ?x? for Gnome desktop.
When you make your icons, if you want transparency, I recommend creating them in your image editing program with a stroked border. This will create a nice anti-aliased border without relying too much on the background being a certain color. I found that this removes the small white jaggies that can often form on the edges of your icons.