O'Reilly logo

Killer Game Programming in Java by Andrew Davison

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

WormChase as an Applet

Figure 3-1 shows the WormChase game as an applet and as an application. It has the same GUI interface as the windowed version: a large canvas with two text fields at the bottom used to report the number of boxes added to the scene, and the time.

Class diagrams showing the public methods are given in Figure 3-10. A comparison with the diagrams for the windowed version in Figure 3-2 show the classes stay mainly the same. The only substantial change is to replace JFrame by JApplet at the top level.

Class diagrams for the WormChase applet

Figure 3-10. Class diagrams for the WormChase applet

Tip

The code for this version of WormChase is in the directory Worm/WormApplet/.

The Worm class is unchanged from the windowed version. The Obstacles class now calls setBoxNumber() in WormChaseApplet rather than WormChase.

WormPanel reports its termination statistics in a different way, but the animation loop and statistics gathering are unchanged. WormChaseApplet handles pausing, resumption, and termination by tying them to events in the applet life cycle. By comparison, WormChase utilizes Window events.

The applet's web page passes the requested frame rate to it as a parameter:

   <applet code="WormChaseApplet.class" width="500" height="415">
      <param name="fps" value="80">
   </applet>

The WormChaseApplet Class

Figure 3-11 shows the class diagram for WormChaseApplet with all its variables and methods.

Figure 3-11. WormChaseApplet ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required