Home arrow Java arrow 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
(Page 1 of 5 )

Deploying Multiple Applets as One

In this section, I describe code you can modify and use as a demonstration framework for your own games. You can distribute it as an applet embedded in a web page, as an executable JAR file, or as a Java Web Start application. The main class, MultiApplet, is structured as a sort of super applet that can contain any number of other applets. As shown in Figure 2-2,MultiAppletallows the players to scroll through a list of your games embedded in this one applet. They can play each one at a time without having to restart the program or reload the page.MultiAppletalso provides a panel for displaying news and documentation about your games.

Figure 2-2.  A MultiApplet example


When a container first initializes anAppletinstance, it first calls itssetStub()method to pass an instance of interfaceAppletStub. TheAppletusesAppletStubto access theAppletContextand other properties.

  package com.croftsoft.core.gui.multi;

  import java.applet.*;
  import java.net.*;

  import com.croftsoft.core.lang.NullArgumentException;


  public final class  MultiAppletStub
    implements AppletStub
  private final Applet parentApplet;

  private boolean active;


  public  MultiAppletStub ( Applet parentApplet )
    NullArgumentException.check ( this.parentApplet = parentApplet );

MultiAppletis an applet that contains other applets. It is also a containee of another applet container, usually a web browser, as shown in Figure 2-2. Acting as a container framework and not as a containee,MultiAppletmust provideAppletStubinstances to its child applets.MultiAppletStubimplements theAppletStubinterface for this purpose.

  public void  appletResize (
    int width,
    int height )
    parentApplet.resize ( width, height );

  public AppletContext  getAppletContext ( )
    return parentApplet.getAppletContext ( );

  public URL  getCodeBase ( )
    return parentApplet.getCodeBase ( );

  public URL  getDocumentBase ( )
return parentApplet.getDocumentBase ( );

  public String getParameter ( String name )
return parentApplet.getParameter ( name );

MultiAppletStubprovides container services to a child applet by delegating calls to theparentApplet, usually an instance ofMultiApplet. For example, when a child game applet retrieves anAppletContextto call a method such asshowDocument(), it uses the sameAppletContextinstance that the parent applet received from the browser.

  public boolean isActive ( )
return active;

  public void  setActive ( boolean active )
this.active = active;

TheAppletStubinterface defines theisActive()accessor method so that the running state of the applet can be determined.MultiAppletStubdefines the corresponding mutator method. Because a child game applet might be inactive while the parent is active, this property is not shared.

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