Home arrow Java arrow Page 5 - Deploying Multiple Java Applets as One

Deploying Multiple Java Applets as One

In this conclusion to a three-part series covering the three different kinds of deployment frameworks you can use with Java games, you'll learn how to deploy multiple Java applets as if they were all one applet. This article is excerpted from chapter two of Advanced Java Game Programming, written by David Wallace Croft (Apress; ISBN: 1590591232).

Author Info:
By: Apress Publishing
Rating: 3 stars3 stars3 stars3 stars3 stars / 9
April 24, 2008
  1. · Deploying Multiple Java Applets as One
  2. · MultiAppletNews
  3. · Lifecycle
  4. · MultiApplet
  5. · CroftSoftCollection

print this article

Deploying Multiple Java Applets as One - CroftSoftCollection
(Page 5 of 5 )


CroftSoftCollectionis the demonstration program that is compiled and launched when you run the default target in the Ant build file. By modifying the constants, you can use it as template code to distribute your own collection of games within aMultiApplet.

  package com.croftsoft.apps.collection;

  import java.awt.Dimension;
  import java.net.URL;

  import com.croftsoft.core.CroftSoftConstants;
  import com.croftsoft.core.gui.multi.MultiApplet;
  import com.croftsoft.core.lang.Pair;

  public final class  CroftSoftCollection
 extends MultiApplet


CroftSoftCollectionextendsMultiApplet so that it can run within an applet container.

 private static final Pair [ ]  APPLET_PAIRS = {
new Pair (
"com.croftsoft.apps.backpropxor.BackpropXor" ),
   new Pair (
  "com.croftsoft.apps.clock.DigitalClock" ),
   new Pair (
     "com.croftsoft.apps.zombie.Zombie" ) };

It defines theAPPLET_PAIRSarray to be passed as an argument toMultiApplet. There is no pre-defined limit to the length of the array. Whenever I create a new game, I usually insert it into the array in alphabetical order. The preceding code shows only three of the array elements.

  private static final String  NEWS_NAME
    = MultiApplet.DEFAULT_NEWS_NAME;

  private static final String  NEWS_HTML
    = "<html><body><pre>"

  private static final String  NEWS_PAGE
    = "http://www.croftsoft.com/portfolio/collection/news/";

When you create your own subclass ofMultiAppletto deploy your own games, you will want to change theseMultiAppletNewsconstants. You will also probably want to load the text ofNEWS_HTMLfrom a resource file within the JAR instead of defining it as a compiled constant as I have done here.

  private static final String  FRAME_TITLE = TITLE;

  private static final String FRAME_ICON_FILENAME
  = CroftSoftConstants.FRAME_ICON_FILENAME;

  private static final Dimension  FRAME_SIZE = null;

  private static final String SHUTDOWN_CONFIRMATION_PROMPT
  = "Close " + TITLE + "?";

You can also customize the frame variables in your own subclass. You will probably want to start by copyingCroftSoftCollection.java, renaming the package and class name, and replacing one of the games with one of your own.

  public static void main ( String [ ] args )
    throws Exception
System.out.println ( APPLET_INFO );

    CroftSoftCollection.class.getClassLoader ( ),

Note that themain()method does not create an instance ofCroftSoftCollection. It simply passes the static constants defined in that class to the staticlaunch()method ofMultiApplet.

  public  CroftSoftCollection ( )
    super (
      NEWS_PAGE );

When theCroftSoftCollectionis used as an applet, however, you must provide a no-argument constructor that passes these constants to the constructor method of the superclassMultiApplet.

  <javac srcdir="${srcdir}" destdir="jar">
    <include name="com/croftsoft/apps/collection/ CroftSoftCollection.java"/>
    <include name="com/croftsoft/apps/backpropxor/ BackpropXor.java"/>
    <include name="com/croftsoft/apps/clock/DigitalClock.java"/>
    <include name="com/croftsoft/apps/zombie/Zombie.java"/>
    manifest="bld/apps/collection/ manifest.txt"/>

Because these game applets are dynamically linked, you have to take care to make sure that they are explicitly included in your build. The preceding code is an excerpt from my Antbuild.xmlfile. Note that if the classes were statically linked, you would only need the firstincludetag.


In this chapter, I introduced three standard Java game deployment frameworks: browser-based applets, executable JARs, and Java Web Start. I discussed the advantages and disadvantages of each with regard to different features including security. Throughout the chapter, I covered programming techniques for
creating your own games including animation thread management, isolating optional packages using custom interfaces and dynamic linking, external browser access through JNLP, using a frame as a stand-alone container, and displaying web pages using Swing. The chapter ended with an examination of the source code of MultiApplet, a reusable framework that you can use to deploy your own games.



1. http://java.sun.com/j2se/1.4.1/docs/ guide/misc/threadPrimitiveDeprecation.html

2. http://java.sun.com/j2se/1.4.2/docs/ guide/plugin/

3. http://java.sun.com/j2se/1.4.2/docs/ guide/plugin/

4. http://java.sun.com/products/ javawebstart/download-spec.html,
     http://java.sun.com/j2se/1.4.2/ docs/guide/jws/developersguide/contents.html

5. Kim Topley, Core Swing Advanced Programming (Upper Saddle River, NJ: Prentice Hall PTR, 2000).


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

blog comments powered by Disqus

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 

Developer Shed Affiliates


© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials