NetRexx applet example

| Multi-hued text applet

This example is an applet which displays some text in a window, with a white background and gradually changing hue.

Here's the source, as a plain ASCII file.

This applet runs a timer thread (like NervousTexxt), but instead of moving the text around, it changes the color. The call to getHSBColor in the paint method set the text color, using values of Hue, Saturation, and Brightness (HSB), each of which should vary between zero and one. You can get more subtle color changes by using values other than one for saturation and brightness.

Also new in this example is the update method; by providing it ourselves (overriding the default), we stop the default background color being displayed for every paint. The image is not drawn directly to the screen; this gives a smoother update and minimizes the time spent in the paint method.

The applet is compiled using the same steps as for the 'Hello World' applet. Unlike 'Hello World', however, this applet takes as a parameter the text to be displayed; to have the applet displayed in World Wide Web page, you need to

1. place the class file in the same directory as the page in which is is to appear
2. refer to it, wherever you want it to appear on the page, with the <applet> tag:

         <applet code="ArchText.class" width=300 height=40>
         <param name=text value="NetRexx!">
         </applet>

   which sets the maximum size for the window in which the applet will appear, and the text that will appear.

You can then view the page with any Java-enabled browser, or with the 'applet viewer' that comes with the Java Development Kit. If you are using such program, you should see the applet below here.

For more details on running applets, see the Hello World applet page.

[ IBM | Help | Legal | Privacy ]