Java
  Home arrow Java arrow Deploying Multiple Java Applets as One
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Deploying Multiple Java Applets as One
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 2 stars2 stars2 stars2 stars2 stars / 5
    2008-04-24

    Table of Contents:
  • Deploying Multiple Java Applets as One
  • MultiAppletNews
  • Lifecycle
  • MultiApplet
  • CroftSoftCollection

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Deploying Multiple Java Applets as One


    (Page 1 of 5 )

    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).

    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

    MultiAppletStub

    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.

    More Java Articles
    More By Apress Publishing


       · This article is an excerpt from the book "Advanced Java Game Programming," published...
     

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

    JAVA ARTICLES

    - 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 ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek