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:
Finally, if your application requires tight integration with the browser (i.e., lots of JavaScript and other browser-based technologies), then this may not be a good strategy for you.
Thoughts/comments?
It should be easy to make a variant of AppletViewer? 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 AppletViewer? itself. If you want it for a test harness you should develop a test harness. -- DaveHarris
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, VisualAge for Java 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.
-- KyleBrown
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 MyApplet? main() method. In which case you might as well also have:
new AppletViewer?( Class.forName(args[0]).newInstance() );in the AppletViewer? class. In which case, why bother with the code in MyApplet??
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. -- DaveHarris
>It doesn't take much to make an Applet run as an application.
You mean a class like Acme.MainFrame? See http://www.acme.com/java/software/Acme.MainFrame.html This class allows applets to stand alone. (However it was written with pre JDK 1.1 event handling.) -- DafyddRees
This page mirrored in JavaIdioms as of April 29, 2006