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

Placeholder Applet

Applets are separate entities on a web page, with their own graphics context that does not "inherit" any visual properties of an applet's environment. Sometimes, however, a more "seamless" integration into the enclosing HTML document might be preferrable in order to hide the fact that a certain functionality is not provided by the browser itself but by a separate Java applet.

The "Placeholder" applet demonstrates how to make an applet "invisible" by adopting the background texture of the underlying web page. Please note, that this approach is not really "fool proof" (depending on the actual texture) and might require some "fine tuning", as the layout mechanisms of different web browsers may vary considerably.

Technical Description

The underlying technique of this applet is extremely simple: assuming that the actual web page uses a bitmap texture to draw the background, the applet just uses the same texture file to fill its own display area. As a result, web page and applet look the same and - in the ideal case - the applet's border disappears. (Note: on web pages without a background texture, the same effect can be achieved by simply adopting the page's background color)

Applet Parameters

Any necessary information such as the URL of the texture file and any geometric displacements (for a better "fit" of the background texture) are passed as applet parameters:

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 "Placeholder" applet may therefore look as follows:

  <APPLET code=Placeholder.class width=300 height=200>
    <PARAM name="Background" value="./Textures/Paper.jpg">
    <PARAM name="XOffset" value="0"><PARAM name="YOffset" value="0">
  </APPLET>

Example

Do you see the applet on the left side? Hopefully not - otherwise you got an example for the limits of the described technique (within your browser and with your display settings)

(Note: it may take a few seconds for the applet to start up, load the background texture of this page and "disappear")

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/Placeholder.html    (last Modification: 23.04.2002)