Digital Edition

SYS-CON.TV
Applets: Make Them Worth The Wait
Applets: Make Them Worth The Wait

Like most web surfers, I just love Java Applets. I love what people are doing with them, and all the nifty new content being developed. Week to week, the number of original and creative applets being added to the Gamelan site, for example, is increasing exponentially (http://www.gamelan.com). At least twice per week I like to go to that site and see what's new.

One thing I can't stand, however, is waiting for other people's applets to start. I mean, I can certainly understand and be tolerant of my own applets, whose many class files must be downloaded not to mention graphics and audio files, which takes time. I must look a little silly, sitting there with baited breath starring at unreactive grey rectangles on my web pages. I know what will eventually show up is worth seeing.

This patience may be due to just a little bit of bias, since I seem to feel any Applet I write is worth waiting for. I can't see why my friends or clients don't immediately share my opinion. The situation seems to go like this: I make some neat-o keen Applet with fancy UI, animation, custom control classes, the works. I happen to be using whatever T1 connection is available to me at the time while I do this development, so applet loading times seem pretty insubstantial. Then I call someone I want to impress (my wife or my mom, most likely) and point them to my URL. More so lately, the sigh of patient, though strained, indulgence I get from the other end of the phone indicates my victim might not enjoy loosing twenty minutes or more waiting for her 28.8K modem to download everything. I imagine other users probably like the delay even less, that is if they are even will to wait at all.

The application initialization delay is not new. A common device is to throw an initialization, or "splash screen", window up to announce your application, and to give the user something to look at while an application loads. Why not do the same thing with applets?

To that end, I'd like to share with you a generic splash screen applet I've developed. The idea is that, whenever you have an applet with potentially long loading and initialization times, it would be best to put up a fancy image or something before that long downloading occurs. Users appreciate that kind of thoughtfulness. Anyway, by giving the user something to look at, it will buy an applet some precious time to perform downloading and initialization.

The FlashSplash applet is a generic splash screen for other applets. When you embed a FlashSplash applet, you specify in the applet's parameters just two things: the URL to a splash screen image to display before loading the target applet, and the name of the target applet class to actually start loading. The FlashSplash applet, upon starting, will download and display the splash screen image before attempting to download and start the target applet. Any applet can be used as a target. Here's sample HTML for a FlashSplash applet that loads an image before loading and starting a target Applet:

<APPLET CODE="FlashSplash.class" WIDTH="400" HEIGHT="300">
<PARAM NAME="splash-SplashImage" VALUE="splash.gif">
<PARAM NAME="splash-TargetApplet" VALUE="MyTargetApplet"> </APPLET>

The trick of the FlashSplash applet is that FlashSplash objects actually act as a proxy AppletStub for the target applet. As you may know, the only way for an applet to communicate with the browser is, ultimately, through the AppletStub interface. (The AppletContext is used also, but it is only through the AppletStub that an applet can get a reference to the AppletContext.) So, The FlashSplash class actually implements the AppletStub interface and hands itself off as an AppletStub to a target applet. The FlashSplash Applet, which is derived from the Panel class also like all applets, also acts as the parent Container for the target applet. The unsuspecting target applet, unaware that its parent Container and AppletStub are actually another applet, merrily runs as expected without too much fuss. (Actually, there are a couple of minor problems, but I'll explain that in a little bit.)

The code for the FlashSplash applet class, which is remarkably simple, is shown in Listing 1. You may notice a little bit of oversimplification where multi-threaded synchronization is concerned, but it makes for much more readable code. I have no doubt an able programmer could make this FlashSplash applet truly thread-safe with minimal effort.

There are two problems with the use of FlashSplash applets with respect to the target applet: First, the FlashSplash and the target applet share a set of parameters. Since the FlashSplash just passes through calls to getParameter( ), then the target Applet has the same parameters the FlashSplash has. This could cause a problem if there were parameter name conflicts. I've tried to minimize that problem by only having two parameters to the FlashSplash applet, and both of them start with the prefix "splash-".

The second, probably more serious, problem is that the target applet is not registered with the browser as a running applet. That means other loaded applet that try to find and communication with the target using AppletContext.getApplet( ) or AppletContext.getApplets( ) will not get a reference to the target applet. Instead, they can only get a reference to the FlashSplash. This is not a horrendous problem, as long as your other applets are aware of FlashSplash. In that case, you could add a getTarget( ) method to the FlashSplash class that the other applets could call to get a reference to the target applet. I leave the addition of that method as a exersize for the reader.

After adding FlashSplash loaders to my web pages, I find it a little easier to convince people to take a look at my applets. I would suggest you do the same for your personal or professional applets.

About Brian Maso
Brian Maso is President of Blumenfeld & Maso, Inc., a Java and Media consulting company. In addition to his involvement in several commercial Java projects, he is also the author of several Java books, including Osborne/McGraw-Hill's upcoming title "Visual J++ From the Ground Up". Brian is the Java guru of DevelopMentor's Java training courses. He has also written several Java white-papers for individual
corporations.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1



ADS BY GOOGLE
Subscribe to the World's Most Powerful Newsletters

ADS BY GOOGLE

DXWorldEXPO LLC announced today that ICOHOLDER named "Media Sponsor" of Miami Blockchain Event by Fi...
SYS-CON Events announced today that IoT Global Network has been named “Media Sponsor” of SYS-CON's @...
The best way to leverage your Cloud Expo presence as a sponsor and exhibitor is to plan your news an...
DevOpsSummit New York 2018, colocated with CloudEXPO | DXWorldEXPO New York 2018 will be held Novemb...
CloudEXPO New York 2018, colocated with DXWorldEXPO New York 2018 will be held November 11-13, 2018,...
DXWorldEXPO | CloudEXPO are the world's most influential, independent events where Cloud Computing w...
Disruption, Innovation, Artificial Intelligence and Machine Learning, Leadership and Management hear...
Enterprises are striving to become digital businesses for differentiated innovation and customer-cen...
DXWorldEXPO LLC announced today that Telecom Reseller has been named "Media Sponsor" of CloudEXPO | ...
"Calligo is a cloud service provider with data privacy at the heart of what we do. We are a typical ...
Consumer-driven contracts are an essential part of a mature microservice testing portfolio enabling ...
Digital Transformation: Preparing Cloud & IoT Security for the Age of Artificial Intelligence. As au...
@DevOpsSummit at Cloud Expo, taking place November 12-13 in New York City, NY, is co-located with 22...
DXWorldEXPO LLC announced today that "IoT Now" was named media sponsor of CloudEXPO | DXWorldEXPO 20...
Containers and Kubernetes allow for code portability across on-premise VMs, bare metal, or multiple ...
SYS-CON Events announced today that Silicon India has been named “Media Sponsor” of SYS-CON's 21st I...
SYS-CON Events announced today that CrowdReviews.com has been named “Media Sponsor” of SYS-CON's 22n...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, disc...
In this presentation, you will learn first hand what works and what doesn't while architecting and d...
Modern software design has fundamentally changed how we manage applications, causing many to turn to...