Scripting Java Applets
22.1. Scripting Java Applets
As discussed in Chapter 14, all Java applets embedded in a web page become part of the Document.applets array. Also, if given a name or id, an applet can be accessed directly as a property of the Document object. For example, the applet created by an <applet> tag with a name attribute of "chart" can be referred to as document.chart.
var chartcolor = document.chart.lineColor; // Read an applet field document.chart.lineColor = "#ff00ff"; // Set an applet field
public int numPoints; public double points;
for(var i = 0; i < document.chart.numPoints; i++) document.chart.points[i] = i*i;
public void setDomain(double xmin, double xmax); public void setChartTitle(String title); public String getXAxisLabel( );
document.chart.setDomain(0, 20); document.chart.setChartTitle("y = x*x"); var label = document.chart.getXAxisLabel( );
var xaxis = document.chart.getXAxis( ); // Get an Axis object var newyaxis = xaxis.clone( ); // Make a copy of it newyaxis.setTitle("Y"); // Call a method of it... document.chart.setYAxis(newyaxis); // and pass it to another method
public String convert(int i); // Convert an integer to a string public String convert(double d); // Convert a floating-point number
var iconvert = document.applets["convert(int)"]; // Get int method iconvert(3); // Invoke the method like this
Copyright © 2003 O'Reilly & Associates. All rights reserved.