Using the loadParams() method available for all NetCharts applets, a developer can easily control the display of one or more chart applets from within a parent applet. The following example shows an HTML document that contains a parent applet and a child barchart applet. The parent sets up the childs initial parameters using loadParams(), and then updates the DataSet1 parameter every 1/10 second using the loadParams() interface.
<title>Embedded Applet Control</title>
<applet name=embedded
code=EmbeddedExample.class
width=450 height=250>
<param name=NFParamScript value = '
Background = (darkGray, RAISED, 5);
'>
</applet>
import netcharts.graphics.*;
import java.lang.*;
import java.awt.*;
import java.util.*;
import java.applet.*;
public class EmbeddedExample extends Applet implements Runnable {
NFBarchartApp bar;
Thread t;
public void init()
{
try {
// NOTE: "this" is passed into NFBarchartApp because
// "this" applet has the appletContext passed in from
// the browser. The appletContext is used in various
// places within NetCharts.
bar = new NFBarchartApp(this);
setLayout(new BorderLayout());
add("Center",bar);
bar.init();
bar.loadParams (
"Header = ('Embedded Applet');"+
"DataSets = ('Fred', blue), ('Sally', red);"+
"BarLabels = 1, 2, 3, 4, 5;"+
"LeftAxis = (white, 'TimesRoman', 16, 0, 0, 20);"+
"DataSet1 = 4, 8, 12, 16, 19;"+
"Update;"
);
bar.start();
} catch (Exception e) {
System.out.println (e.getMessage());
}
}
public void start()
{
t = new Thread(this);
t.start();
}
public void stop()
{
t.stop();
}
public void run()
{
int i = 0;
String s;
while (true){
try {
switch(i){
case 0: s = "1, 3, 5, 15, 3"; break;
case 1: s = "3, 2, 8, 13, 14"; break;
default: s = "5, 0, 9, 11, 3"; break;
}
bar.loadParams("DataSet1 = "+s+";Update;");
Thread.currentThread().sleep(100);
i++;
if (i >= 3)
i = 0;
} catch (Exception e) {
System.out.println (e.getMessage());
}
}
}
}