Andreas Rozek Hints for Reading List of Recent Changes Guestbook Entry Contact the Author  Deutsche Version  HomePage Previous Topic Next Topic  First Page of Current Topic Next Page Previous Page

Clock Applet

The "Clock" applet periodically displays the actual time. It is a simple example for a "real" applet which uses the "Placeholder" technique to seamlessly integrate an applet into an HTML document.

Technical Description

Instead of re-implementing the code of "Placeholder", "Clock" simply "extends" that applet. A look into the source code illustrates where "Placeholder" methods have to be called in order to use their functionality:

public class Clock extends Placeholder {
  public void init () {
    super.init();                                // handles any given parameters
    ...
  };

  public synchronized void paint (Graphics Graf) {
    super.paint(Graf);                                        // draw background
    ...
  };
};

By this means, inheritance significantly simplifies applet programming. However, please note the following details:

  • an applet which extends "Placeholder" and requires additional parameters should completely redefine the "ParameterInfo" field but include the three parameters needed for "Placeholder";

  • whenever the "Clock" applet (or any other applet extending "Placeholder" ) shall be used in an HTML document, the "Placeholder" class must also be available. Otherwise, the browser won't be able to run the applet.

Applet Parameters

"Clock" uses the same applet parameters as "Placeholder" (which are repeated here for sake of completeness only):

Background

specifies the URL of a (GIF or JPEG) file containing the background texture for both web page and Java applet. Either an absolute URL or one relative to the underlying HTML document may be given;

XOffset

optionally specifies a horizontal displacement. The position of the background texture will be shifted by the given number of pixels in order to fit seamlessly into the enclosing web page;

YOffset

optionally specifies a vertical displacement. The position of the background texture will be shifted by the given number of pixels in order to fit seamlessly into the enclosing web page;

A typical invocation of the "Clock" applet may therefore look as follows:

  <APPLET code=Clock.class width=80 height=20>
    <PARAM name="Background" value="./Textures/Paper.jpg">
    <PARAM name="XOffset" value="0"><PARAM name="YOffset" value="0">
  </APPLET>

Example

Provided that your Browser is able to run Java applets, you should be now see a periodically updated time display on the left side. (Because of the author's use of this applet, the display is right-justified)

Source Code

The source code of this applet is available for download:

Disclaimer

Please, consider also the author's Disclaimer!

http://www.Andreas-Rozek.de/Java/Applets/Clock.html    (last Modification: 23.04.2002)