Applet-To-Applet Control

Using the loadParams() method available for all NetCharts applets, a developer can easily control the display of one or more chart applets from another applet. The following example shows an HTML document that contains two applets, one of them contains a single button, while the other is a simple barchart. When the button is pressed, the background color of the barchart is changed to blue. This simple example of applet-to-applet control can be expanded, using the loadParams() method to implement many different control situations.

HTML File

<title>Applet-To-Applet Control</title>

<applet name=control
	code=Control.class
	width=200 height=100>
</applet>

<applet name=barchart
        code=NFBarchartApp.class
        width=450 height=250>

<param  name=NFParamScript      value = '
	Background = (white, NONE);
	Header     = ("Weekday Network Load", black, "TimesRoman", 20);
	BarLabels  = "Mon", "Tue", "Wed", "Thu", "Fri";
	DataSets   = ("Server #1", blue), ("Server #2", red);
	DataSet1   = 100, -25, 75, 63, -46;
	DataSet2   = 85, 45, 10, -67, 10;
'>
</applet>

JAVA File

import java.applet.*;
import java.awt.*;

public class Control extends Applet
{
	private NFBarchartApp bar = null;

	public void init ()
	{
		add (new Button("Change Background"));
	}

	public boolean action (Event e, Object o)
	{
		bar = (NFBarchartApp)getAppletContext().getApplet("barchart");

		if (bar == null) {
			System.out.println ("Unable to access Barchart");
		} else {
			bar.loadParams ("Background = (blue)");
			bar.loadParams ("Update");
		}
		return true;
	}
}