Writing to the Java Console Before you try out these techniques, open the Java console. You can find it under the OPTIONS menu in Netscape. When you have it open, click on the clear button to remove its default message. One thing to note is that the console is NOT a \"stay on top \" window. It will immediately disappear behind any other window on which you click.
ConsoleTest This code is straight from Netscape's example. Below are a button and a text field. Type whatever you want into the text field and click the button labeled "Write". Find the console, which is likely now under Netscape, and you will see that your message has been printed to the console.
The console contents are persistent; if you close and open the console, your text will still be there. Unfortunately, the console does not act as an input device; you cannot read it. The "Write" button contains an onclick routine,
which calls this function:
For our next example, let's do something a little more sophisticated and, in the process, we will use the new split method of the string object. The split method has the following syntax:
Note that the method constructs the new array for you. You can find the length with
We will also compare the ease of debugging with alert boxes, which up to now have been your only choice, and console debugging. In a Netscape 2.0 page, we calculate a mean and standard deviation of some values. Each has to be entered into an input box, which means that the number of values one can input is limited by the number of input boxes. In this case, we will simply provide a text area and a place to provide the separator which you will use. The example uses a comma as a separator but you can experiment with different ones. The input controls are followed by four buttons:
21.6,22.8,19.3,14.4,20.2,21.1,23.0Separator Character: Debug On:
This section uses a simple applet developed by Morphic Molecules. It just presents a single line of text in a pleasant setting. It does not scroll, blink, bounce or fade. While these special effects might seem nifty, they are really annoying on a fast computer where text scrolls, blinks, bounces, or fades so fast that the use cannot read it. Unlike most applets, its parameters are addressable and, therefore, accessible to Javascript. In order to use the applet, download the class file and place it in the same directory as your html file (or set the code base parameter to where you are going to put it). You can also download the source, which could have a number of enhancements made to it. Get both the class and the source along with a short HTML file in a zip file if you wish. If you use Symantec's Cafe to build Java applets, download a zip file with the complete project files. This applet has ten variables which have public get and set methods. Set methods take a single string parameter and get methods return a single string parameter. Variables passed via applet parameters and get/set methods are error checked. Variable set by direct access by Javascript are NOT checked at all. Be careful! Further, some variable types cannot be directly passed, such as colors, where a string representation of a color must be laboriously converted into a color object. Consequently, the variables are private but accessible with get and set methods. The following table describes these variables, their uses and the methods available to get and set them.
Public variables of the MessageBox class
Property
Type
Permissible Values
Notes
vmargin
applet.setVMargin(string) string = applet.getVMargin()
hmargin
applet.setHMargin(string) string = applet.getHMargin()
borderwidth
applet.setBorderWidth(string) string = applet.getBorderWidth()
theFontName
applet.setFontName(string) string = applet.getFontName()
theFontStyle
applet.setFontStyle(string) string = applet.getFontStyle()
theFontSize
applet.setFontSize(string) string = applet.getFontSize()
theMsg
applet.setMsg(string) string = applet.getMsg()
justification
applet.setJustification(string) string = applet.getJustification()
theFontColor
applet.setFontColor(string) string = applet.getFontColor()
theBGColor
applet.setBGColor(string) string = applet.getBGColor()
theBorderColor
applet.setBorderColor(string) string = applet.getBorderColor()
theInset applet.setInset(string) string = applet.getInset()
This page was last updated on
Mail comments about Morphic Molecules pages to everett@txdirect.net