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.

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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access