Embedding Java applets in your HTML is a simple matter of defining APPLET code and editing the parameters to suit your particular setup. The Java section of the DataHub API includes several example classes to help you begin to build dynamic web pages. See Section 2.5, “Writing your own Java class” for information on how to build your own Java applets to display live data from the DataHub. Our example applets include:
You can see the rendered widgets by pointing your browser at the DataHubViewer.html file that is included in the API installation:

The applets that implement these widgets are compiled into the DataHubViewer.jar file.
![]() | In order to use the DataHubViewer.jar file, you will need to copy it to a directory accessible by your web server. |
Our model for displaying dynamic data in a web page uses a Base applet and Listener applets to reduce network bandwidth requirements and increase the speed of updates in the page.

In our model, any web page that connects to the DataHub needs to include at least one applet derived from the DataHubBaseApplet class. We call this applet the Base applet. The Base applet makes the connection to the DataHub and registers for all point changes in a specific DataHub domain. In other words, the Base applet receives the live data from the DataHub. In addition to displaying data, Base applets also relay dynamic data to other applets in the web page, which we call Listener applets (see below). You can have as many Base applets as you like in a page, but each one will require a separate connection to the DataHub. The miniumum you will need is one per DataHub domain.
There are two Base applets to choose from in the Java API. The first is DataHubViewer.class, which displays a table of dynamic data in a web page. The second is DataHubLink.class, which simply puts a small "Powered by Cogent" logo on the screen. Using these as examples, you can build your own Base applets to display the data from the Cascade DataHub in any way you like.
The purpose of the Base applets is threefold:
Listener applets also connect to the Cascade DataHub, but they do so through the Base applet connection. The data coming from the DataHub goes to the Base applet first. From there it is transferred to all Listener applets on the same web page. This dramatically improves the speed of the connection and reduces network traffic. You can add as many Listener applets to the page as you like with little impact on data transfer rates.
We have included a number of example Listener applets you can use to build dynamic web pages or extend to make your own applets. These include:
The recommended data model is to have one Base applet per page, feeding multiple Listener applets.
Embedding Java applets in a web page is complicated by inconsistencies between different browsers. To simplify this process we have created a shortcut that reduces the amount of HTML code you have to write.
Internet Explorer requires a Java plug-in to recognize and correctly display the APPLET tag. To have IE download and install the Java plug-in you must ensure it has the correct information about what version of the plug-in to install, and where to go to download it. This information is provided in the following OBJECT tag.
<OBJECT CLASSID="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93" CODEBASE="http://java.sun.com/update/1.5.0/jinstall-1_5_0-windows-i586.cab#Version=1,5,0" WIDTH="0" HEIGHT="0"> <PARAM NAME="java_code" VALUE="cogent/DataHubDummy.class"> <PARAM NAME="java_codebase" VALUE="http://developers.cogentrts.com/java/"> <PARAM NAME="java_archive" VALUE="DataHubViewer.jar"> </OBJECT>
If the Java plug-in has already been installed in the browser, then IE will simply load the DataHubDummy code and execute it. The code does nothing and simply returns control to the browser.
If the Java plug-in has not been installed, then this OBJECT code instructs IE where to go to download the plug-in. After the plug-in is installed, the Java code is run and control is once again returned to the browser.
After IE has installed the Java plug-in it will then be able to recognize the APPLET tag in future web pages it visits. We take advantage of this fact to eliminate the need to wrap each APPLET tag in a duplicate OBJECT tag, thus reducing the amount of HTML code needed to embed each applet.
Firefox, Mozilla and NetScape all recognize the APPLET tag and will load the Java plug-in (if needed) when they first encounter the APPLET tag in your web page.
![]() | We recommend placing this shortcut OBJECT tag in your web pages before any APPLET code definitions. This will ensure that IE recognizes the APPLET tags in the rest of your web page. |
To make a connection to the Cascade DataHub, you need to use a Base applet, such as DataHubViewer.class or DataHubLink.class, somewhere in your page. The DataHubViewer.class links to the DataHub and inserts a table of all the data into your page. The DataHubLink.class, on the other hand, links to the DataHub and inserts a small text message "Powered by Cogent" into your page. Here is an annotated version of the code using DataHubViewer.class:
<APPLET CODE="" WIDTH="600" HEIGHT="211"> (1) <PARAM NAME="java_code" VALUE="cogent/DataHubViewer.class"> (2) <PARAM NAME="java_codebase" VALUE="http://developers.cogentrts.com/java/"> (3) <PARAM NAME="java_archive" VALUE="DataHubViewer.jar"> (4) <PARAM NAME="bgcolor" VALUE="ffff00"> (5) <PARAM NAME="fgcolor" VALUE="000000"> (6) <PARAM NAME="host" VALUE="developers.cogentrts.com"> (7) <PARAM NAME="port" VALUE="4600"> (8) <PARAM NAME="domain" VALUE="test"> (9) <PARAM NAME="name" VALUE="testdomain"> (10) Your browser is not Java enabled (11) </APPLET>
| (1) | Instructs the browser to reserve space in the page for the applet. |
| (2) | Calls the code of the widget class. |
| (3) | Tells the server where the .jar file for the code is located. |
| (4) | Identifies the .jar file that contains the code. This same .jar file is used for all the classes in this API. |
| (5) | Sets the background color. |
| (6) | Sets the foreground color (the color of the text). |
| (7) | Identifies the host machine where the DataHub is running. This must be the server machine itself. |
| (8) | Identifies the port number of the connection. |
| (9) | Identifies the DataHub domain where the data resides. |
| (10) | Names this applet. This name is used by any DataHubListeners (see below). |
| (11) | Message displayed if the browser does not have Java enabled. The browser will attempt to download the appropriate Java plug-in. We use the OBJECT tag shortcut described above to instruct the browser where to find the Java plug-in. |
Once a connection has been established with a DataHubBaseApplet, you can use any number of DataHubListener applets on your web page. These can access single or multiple values from the Cascade DataHub that were brought in by the DataHubBaseApplet. Below is an example of a Listener applet, DataHubLabel, which displays and dynamically updates the value of a data point.
<APPLET CODE="" ALIGN="absmiddle" WIDTH="40" HEIGHT="20"> <PARAM NAME="java_code" VALUE="cogent/DataHubLabel.class"> <PARAM NAME="java_codebase" VALUE="http://developers.cogentrts.com/java/"> <PARAM NAME="java_archive" VALUE="DataHubViewer.jar"> <PARAM NAME="bgcolor" VALUE="ffffff"> <PARAM NAME="fgcolor" VALUE="ff0000"> <PARAM NAME="name" VALUE="DataHubItem"> <PARAM NAME="points" VALUE="MV_001"> (1) <PARAM NAME="parent" VALUE="testdomain"> (2) Your browser is not Java enabled </APPLET>
Copyright © 1995-2006 by Cogent Real-Time Systems, Inc. All rights reserved.