1  <html>
  2  <head>
  3  <title>JavaScript Example:  LiveConnect II</title>
  4  
  5  <SCRIPT LANGUAGE="JavaScript">
  6  <!-- hide script from old browsers
  7  
  8  var codebase = "http://www.npac.syr.edu/projects/tutorials/Java/examples/Geometry/MyPolygon/";
  9  var rootname = "TriangleTest";
 10  
 11  // Handle button clicks:
 12  var regexp = /^\d+$/;
 13  function setDepth() {
 14    var s = document.myForm.depthStr.value;
 15    if ( regexp.test( s ) ) {
 16      // Assign a value to a public variable (maxDepth) of the applet
 17      // using a public method string2int():
 18      document.TriangleTest.maxDepth = document.TriangleTest.string2int( s );
 19      // Invoke applet's repaint() method:
 20      document.TriangleTest.repaint();
 21    }
 22    document.myForm.depthStr.select();
 23    document.myForm.depthStr.focus();
 24  }
 25  
 26  // end script hiding -->
 27  </SCRIPT>
 28  
 29  </head>
 30  
 31  <body onLoad="document.myForm.depthStr.value = 5; setDepth();">
 32  
 33  This HTML document illustrates JavaScript to Java communication
 34  via LiveConnect. <P>
 35  
 36  <applet codebase="&{codebase};" code="&{rootname};.class"
 37          name="TriangleTest" width=300 height=300>
 38    <param name="maxDepth" value="5">
 39  </applet>
 40  <P>
 41  
 42  <FORM NAME="myForm" onSubmit="setDepth(); return false">
 43    Maximum depth:&nbsp;<INPUT TYPE="text" SIZE=20 NAME="depthStr" 
 44    onChange="setDepth();">
 45    <INPUT TYPE="button" VALUE="Redraw" onClick="setDepth();">
 46  </FORM>
 47  <P>
 48  
 49  View <A HREF="&{codebase};&{rootname};.java.html" 
 50  TARGET="_blank">Java source file</A>
 51  
 52  </body>
 53  </html>