A technique that I have found to be very useful is to take the time to make sure that JavaApplet
s can be run as applications too.
This takes some additional work, but in the long run (particularly for large systems), it is definitely worth it. In particular, it confers several benefits that I appreciate:
- The system can be unit tested more easily. Stopping and restarting a WebBrowser (all too common) is painful (shades of DOS Alt-Ctl-Del for pointer errors comes to mind).
- It can give you more flexibility down the road if you decide to make the system an application.
It does introduce some complexities though. In particular, you will need to maintain 2 versions of the code associated with your applet/application. Additionally, if you are depending upon WebServer
authentication (such as HTTP Basic Authentication), you will need to build some kind of dialog which prompts the user for their login and password.
and other browser-based technologies), then this may not be a good strategy for you.
My few applets are designed to download as quickly as possible. So they don't contain any application code that they don't need to do their applet job.
It should be easy to make a variant of Applet
Viewer than can turn any applet into an application by configuring it with the applet's class name. I've never felt the need for this because I can do what I need with Applet
Viewer itself. If you want it for a test harness you should develop a test harness.
It doesn't take much to make a JavaApplet
run as an application. All you have to do is write a main() method that creates a frame and slaps the applet into the frame. In fact, VisualAgeForJava
automatically generates this kind of code for you when you create an applet. I tend to think that the benefits of writing the few additional lines of code outweigh the (few) additional bytecodes that the method generates.
Well, it takes a little more than that. You need to support getParameter() and a bunch of other stuff. It can (and should) be factored out, so you end up with something like:
new UK.co.bhresearch.Applet.AppletViewer( new MyApplet() );
in the My
Applet main() method. In which case you might as well also have:
new AppletViewer( Class.forName(args).newInstance() );
in the Applet
Viewer class. In which case, why bother with the code in My
I agree that removing those 100 bytes or so from the applet is an extreme optimization, but in some cases it's justified, given how little extra utility they add.
>It doesn't take much to make an Applet run as an application.
You mean a class like Acme.Main
This class allows applets to stand alone. (However it was written with pre JDK 1.1 JavaEventHandling