Note: This page is lifted from a Nick Heinle tutorial.

The dynamictext  applet is embedded in this page, and connected it to JavaScript using a simple form. Enter some text, then press setText.

Not quite as exciting as the other three examples. The point is, however, that this can be made very simple or very elaborate. The first step in adding dynamicText, or any Java app to your site, is to embed it with the APPLET tag.

    <APPLET NAME = "dynamictextApp" CODE = "dynamictext.class" WIDTH = 200 HEIGHT = 25>
    <PARAM NAME = "x_pos" VALUE = "2">
    <PARAM NAME = "y_pos" VALUE = "15"> 
    <PARAM NAME = "center" VALUE = "0"> 
    <PARAM NAME = "fontface" VALUE = "TimesRoman">
    <PARAM NAME = "fontsize" VALUE = "16">
    <PARAM NAME = "fontcolor" VALUE = "0,0,0"> 
    <PARAM NAME = "bgcolor" VALUE = "255,255,255">
    </APPLET>

The name of the dynamicText class file, while contains the compiled Java code, is "dynamictext.class". The dynamicText app has eight initial parameters; all must be included for it to work. The first two, "x_pos" and "y_pos" control the placement of the text (in pixels) in relation to the upper left hand corner of the applet. The next, "center", determines if the text will be centered. Setting this to "1" will center the text, anything else will just be ignored.

The next three; "fontface", "fontsize", and "fontcolor", speak for themselves. The only thing that you should note is that the color of the font is done in RGB, as opposed the hex (00, FF etc.). The values for each color, which are between 0 and 255, must be in this form: "rrr, ggg, bbb". For instance, if I want straight blue text, I'd use this RGB color in the "fontcolor" parameter : "0,0,255". The same rule applies to the "bgcolor" parameter, which controls the color of the applet's background.

Now on to the fun part: controlling the applet throught JavaScript. Referring to an applet in JavaScript is very easy, just use its name (The name paramter in the APPLET tag specifies the name). In this case, I can referr to the dynamicText applet like this: "document.dynamictextApp". The dynamicText applet has a group of Methods, which are very similar to functions, that allow JavaScript to control what's happening in the applet. The first and foremost is the setText() Method, which allows you to change the text that the applet is displaying. To do this, simply pass setText() a string of text:

    document.dynamictextApp.setText("Some Text");

This would display "Some Text" in the dynamicText applet window. There are a number of other things that can be changed on the fly using JavaScript, and here they are:

Font Size: must be an integer. This would be size 12 pt:

    document.dynamictextApp.setfSize(12);

Font Color: must be in the RGB format. This would be red:

    document.dynamictextApp.setfColor("255,0,0");

Height and Width positioning: This would be 10 pixels down, 10 pixels over left:

    document.dynamictextApp.setXY(10,10);

How about a few more for practice? Let's make the font color a light grey, change the font size to 24, and make the text say, "I am the text.":

    document.dynamictextApp.setfColor("190,190,190");
    document.dynamictextApp.setfSize(24);
    document.dynamictextApp.setText("I am the text.");