The generic JWAVE applet lets you do this with very little programming. All you need to write is the JWAVE wrapper function (in PV-WAVE) and some simple HTML code. The generic applet takes care of the rest of the work, such as contacting the server, opening a connection to the server, and retrieving data and graphics from the server.
This section discusses the HTML code used to display the applet and the JWAVE wrapper function that is executed by PV-WAVE on the server.
Figure 2-1 2D plot displayed using the generic JWAVE applet
examples similar to this one in the directory:
TIP: You can find
VNI_DIR/classes/jwave_demos/JWaveApplet
VNI_DIR\classes\jwave_demos\JWaveApplet
VNI_DIR
is your main Visual Numerics installation directory.
Example 2-1 Simple HTML code for calling the generic JWAVE applet.
HTML
![]()
HEAD
![]()
TITLE
JWaveApplet Example 1
/TITLE
![]()
/HEAD
![]()
BODY
![]()
APPLET CODE="com.visualnumerics.jwave.JWaveApplet" CODEBASE="../../classes" ARCHIVE="JWave.jar, JWaveConnectInfo.jar" WIDTH=450 HEIGHT=500
![]()
PARAM NAME="FUNCTION" VALUE="TESTPLOT"
![]()
PARAM NAME="TRANSIENT_SESSIONS" VALUE="YES"
![]()
/APPLET
![]()
/BODY
![]()
/HTML
![]()
CODE
, CODEBASE
, ARCHIVE
, WIDTH
, and HEIGHT
parameters are standard applet parameters used to call any applet. The CODE
parameter gives the class name of the applet. This class was installed on the server when you installed JWAVE. The CODEBASE
parameter tells the applet where to find the root of the Java class tree. The ARCHIVE
parameter specifies Java Archive (JAR) files that contain the JWAVE Java class files that are required by the applet. The JAR file called JWave.jar
is shipped with JWAVE and contains all of the class files you need to develop JWAVE client applications, including the JWaveApplet class file. The JAR file JWaveConnectInfo.jar
describes how to connect to the server. The WIDTH
and HEIGHT
parameters simply specify the size of the applet display area.
TIP: The generic JWAVE applet accepts a number ofPARAM
tags, many more than are used in this example. Refer to the Javadoc reference on the JWaveApplet class for detailed information on all of the generic applet's PARAM tags. For information on Javadoc, see Using the JWAVE Javadoc Reference.
FUNCTION
parameter takes one argument, TESTPLOT
, which is the name of the JWAVE wrapper function on the server. This is the PV-WAVE function that is executed on the server. This function will be described later. It creates a plot and sends it back to the client. By setting the
TRANSIENT_SESSIONS
parameter to YES
, we are asking the JWAVE Manager on the server to shut down the PV-WAVE session as soon as the client-server transaction is completed. This request makes sense because all we want is to get back a single picture from PV-WAVE. No further processing is required. Therefore, it is best to shut down the PV-WAVE session. If TRANSIENT_SESSIONS
were set to NO
(the default), the PV-WAVE session would remain active on the server until explicitly terminated (when the applet is unloaded, which occurs when you move to a new HTML page in your browser).
Example 2-2 A minimal JWAVEwrapper function
FUNCTION TESTPLOT, client_data PLOT, FINDGEN(10), Linestyle=0, PSym=6 RETURN, 0 END
In the next example, we'll add some JavaScriptTM functions to the client HTML file. These functions will enable the client to control the appearance of the graphic generated by PV-WAVE on the server.
The next section discusses how to pass parameters and data from client to server using JavaScript.
TIP: There are many manuals available on JavaScript in bookstores. For online information about JavaScript, refer to the JavaScript Guide on the Netscape Web site at:
http://developer.netscape.com/docs/manuals
TIP: Visual Numerics has provided several applet demonstrations, including the one used in this example, with your JWAVE installation. For information on running the demonstration applets, see Running the Applet Demonstrations.
In this example, we use JavaScript to call methods that are defined in the JWAVE generic applet.
JWaveApplet (in the
TIP: For detailed information on the generic applet methods that can be used with JavaScript, refer to the Javadoc page on
jwave
package). For information on Javadoc, see Using the JWAVE Javadoc Reference. Example 2-3 HTML file withJavaScript calls
HTML
![]()
HEAD
![]()
TITLE
JWaveApplet Example 2
/TITLE
![]()
/HEAD
![]()
SCRIPT LANGUAGE=JavaScript
// Update the plot function updatePlot() { if (! document.JWavePlot.isStarted()) { // Wait for applet to start before trying to updatePlot setTimeout("updatePlot()", 250); return; } // Must get a session before we can set anything document.JWavePlot.openSession(); // Set background and data line colors document.JWavePlot.setNamedColor('BACKGROUND', 'LightGray'); document.JWavePlot.setNamedColor('LINE', 'Blue'); // Set line style (dashed) document.JWavePlot.setParam('LINESTYLE', 2); // Turn off plot symbols document.JWavePlot.setParam('SYMBOL', 0); // Update the plot (and close the transient session) document.JWavePlot.execute(); }
BODY onLoad="updatePlot()"
![]()
H1
JWaveApplet Example 2
/H1
![]()
APPLET NAME="JWavePlot" CODE="com.visualnumerics.jwave.JWaveApplet" CODEBASE="../../" ARCHIVE="JWave.jar, JWaveConnectInfo.jar" WIDTH=450 HEIGHT=500
![]()
PARAM NAME="FUNCTION" VALUE="TESTPLOT"
![]()
PARAM NAME="EXECUTE_ON_START" VALUE="NO"
![]()
PARAM NAME="TRANSIENT_SESSIONS" VALUE="YES"
![]()
/APPLET
![]()
/BODY
![]()
/HTML
![]()
updatePlot
, that is embedded in the HTML file. First, the "if" clause with the
setTimout
function ensures that the plot does not update until the applet is ready. The next call in this function is:
document.JWavePlot.openSession();
document
is the object name referring to the browser window itself. JWavePlot
is the name by which JavaScript recognizes the applet (specified with the applet's NAME
tag), and openSession
is a method defined in the generic JWAVE applet, JWaveApplet
(specified with the CODE
tag). We need to call
openSession
to open a connection with the JWAVE Manager on the server. Normally, the applet connects and executes immediately upon startup. But we want to delay the execution until the parameters are set. That is, we want to open a session, set the parameters, and then execute the JWAVE wrapper. The next few JavaScript calls set color values and parameters to be sent to the JWAVE wrapper function on the server.
document.JWavePlot.setNamedColor('BACKGROUND', 'LightGray'); document.JWavePlot.setNamedColor('LINE', 'Blue'); document.JWavePlot.setParam('LINESTYLE', 2); document.JWavePlot.setParam('SYMBOL', 0);
setNamedColor
sets a parameter name and a color value. In the JWAVE wrapper function on the server, these parameters are interpreted by corresponding GETPARAM functions, and their values are retrieved. Once retrieved, those parameter values can be plugged directly into PV-WAVE functions. In this case, TESTPLOT
is going to plug the parameters set in the HTML file into the PV-WAVE PLOT command. The final call in our JavaScript function is:
document.JWavePlot.execute();
execute
method sends parameters to the server and executes the JWAVE wrapper function. This in turn generates a plot, which is sent back to the client and displayed. Finally, we use a couple of
PARAM
tags to prevent the applet from executing the JWAVE wrapper immediately when the applet starts. First, we need to set the EXECUTE_ON_START
parameter to NO
. This parameter prevents the JWaveApplet from executing when the applet starts. Then, having told the applet what not to do, we need to tell the applet what to do when it is loaded. This is the purpose of the onLoad
parameter that is set in the applet's BODY
tag. The onLoad
parameter tells the applet to execute the JavaScript function updatePlot
when the HTML page loads. And, to reiterate, this JavaScript function does the following:
TIP: Because JavaScript supports form objects, you can use JavaScript to create interactive GUIs for your client applets without any Java programming. For information about more complex JavaScript demonstrations created by Visual Numerics, see Running the Applet Demonstrations.
The functions used to unpack data sent from the client are: GET_NAMED_COLOR and GETPARAM. PLOT commands are then constructed using the unpacked values.
You can find the following JWAVE wrapper in:
VNI_DIR/jwave-3_0/lib/user/testplot.pro
VNI_DIR\jwave-3_0\lib\user\testplot.pro
VNI_DIR
is the main Visual Numerics installation directory.
Example 2-4 JWAVEwrapper function, TESTPLOT
FUNCTION TESTPLOT, client_data ; get colors black = '000000'xL white = 'FFFFFF'xL back_color = GET_NAMED_COLOR("BACKGROUND", Default = black) axis_color = GET_NAMED_COLOR("AXES", Default = white) line_color = GET_NAMED_COLOR("LINE", Default = white) psym_colors = GET_NAMED_COLOR("SYMBOLS", Default = [white], /Color_Set) ; get data data = GETPARAM(client_data, 'DATA', /Value, Default = FINDGEN(10)) ; get plot attributes linestyle = GETPARAM(client_data, 'LINESTYLE', /Value, Default = 1) psym = GETPARAM(client_data, 'SYMBOL', /Value, Default = 6) ; Plot axes PLOT, data, /NoData, Background = back_color, Color = axis_color ; plot lines IF linestyle GE 0 THEN $ OPLOT, data, Linestyle = linestyle, Color = line_color ; plot symbols IF psym NE 0 THEN $ OPLOT, data, PSym = ABS(psym), Color = psym_colors RETURN, 0 END
The
data = GETPARAM(client_data, 'DATA', /Value, Default = FINDGEN(10))
PLOT, data, ...
NOTE: Detailed information on the parameters and keywords of the GETPARAM and GET_NAMED_COLOR functions are available in the PV-WAVE online help system and in Appendix A, JWAVE Wrapper API.
The
setNamedColor
method, that color can be retrieved by PV-WAVE with the GET_NAMED_COLOR function. The GET_NAMED_COLOR function converts a named color specified on the client into a color index that PV-WAVE can understand. For instance, the returned value from GET_NAMED_COLOR can be used with the PLOT command's Background keyword.
For example, GET_NAMED_COLOR might return a color index for the background color of a 2D plot.
back_color = GET_NAMED_COLOR("BACKGROUND", Default = black) data = GETPARAM(client_data, 'DATA', /Value, Default = FINDGEN(10)) PLOT, data, Background = back_color
applets, you must have a working installation of JWAVE and the JWAVE Manager must be running on the server. To run these demonstrations, you must also have a browser that supports JDK 1.1.
NOTE: To run these
$VNI_DIR/classes/jwave_demos/JWaveApplet
VNI_DIR\classes\jwave_demos/JWaveApplet
FORM
tags. There are some JavaScript helper functions provided in this page to help the FORM
tags interact with JWAVE. The wrapper function still generates its own data.