Home arrow Java arrow Page 9 - Deployment Frameworks

Deployment Frameworks

Once you have learned how to program games in Java, you will want to be able to deploy them on different types of deployment frameworks. This article will cover browser applets, executable JARs, and Java Web Start. It is excerpted from the book Advanced Java Game Programming written by David Wallace Croft (Apress, 2004; ISBN 1590591232).

Author Info:
By: Apress Publishing
Rating: 4 stars4 stars4 stars4 stars4 stars / 11
April 12, 2005
  1. · Deployment Frameworks
  2. · Reading from a JAR File
  3. · Signing Applets
  4. · Deploying with Java Web Start
  5. · Isolating Optional Packages
  6. · Deploying Multiple Applets as One
  7. · Lifecycle
  8. · MultiApplet
  9. · CroftSoftCollection

print this article

Deployment Frameworks - CroftSoftCollection
(Page 9 of 9 )


CroftSoftCollection is 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 a MultiApplet.

 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


CroftSoftCollection extends MultiApplet 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 the APPLET_PAIRS array to be passed as an argument to MultiApplet. 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>" + APPLET_INFO +

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

When you create your own subclass of MultiApplet to deploy your own games, you will want to change these MultiAppletNews constants. You will also probably want to load the text of NEWS_HTML from 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 copying CroftSoftCollection.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 );

   MultiApplet.launch (
     CroftSoftCollection.class.getClassLoader ( ),

Note that the main() method does not create an instance of CroftSoft-Collection. It simply passes the static constants defined in that class to the static launch() method of MultiApplet.

 public CroftSoftCollection ( )
   super (
     NEWS_PAGE );

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

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

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 Ant build.xml file. Note that if the classes were statically linked, you would only need the first include tag.


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/

  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,

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

Further Reading

Schmidt, Rene W. Java Network Launching Protocol & API Specification. http://java.sun.com/products/javawebstart/download-spec.html. Sun Microsystems. Java Plug-in 1.4.2 Developer Guide. http://java.sun.com/j2se/1.4.2/docs/guide/plugin/. Sun Microsystems. Java Web Start 1.4.2 Developer Guide.

http://java.sun.com/j2se/1.4.2/docs/guide/jws/ developersguide/contents.html. Sun Microsystems. “Why Are Thread.stop, Thread.suspend, Thread.resume and Runtime.runFinalizersOnExit Deprecated?”

. html.

Topley, Kim. “JEditorPane and the Swing HTML Package.” Chapter 4 in Core Swing Advanced Programming. Upper Saddle River, NJ: Prentice-Hall PTR, 2000.

This article is excerpted from Advanced Java Game Programming by David Wallace Croft (Apress, 2004; ISBN 1590591232). Check it out at your favorite bookstore today. Buy this book now.

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-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials