Modify the table entries and press the button to update the piechart.
Applet Source Code
import java.awt.*;
import java.applet.*;
// This applet allows the user to modify the
// label, color and value associated with some
// pie slices and then creates a parameter definition
// string that is passed to the piechart applet.
public class NFPiechartForm extends Applet
{
NFPiechartApp pie = null;
TextField value[] = new TextField[7];
TextField label[] = new TextField[7];
Choice color[] = new Choice[7];
public void init ()
{
Panel panel = new Panel();
panel.setLayout (new GridLayout (4, 3));
createRow (panel, 0, 23, "red", "Mon");
createRow (panel, 1, 37, "magenta", "Tue");
createRow (panel, 2, 12, "green", "Wed");
createRow (panel, 3, 25, "orange", "Thu");
setLayout (new BorderLayout());
add ("North", panel);
add ("South", new Button ("Update Piechart"));
}
public void createRow (Panel panel, int i,
int val, String col, String lab)
{
label[i] = new TextField (lab);
panel.add (label[i]);
color[i] = new Choice();
color[i].addItem ("red");
color[i].addItem ("blue");
color[i].addItem ("green");
color[i].addItem ("magenta");
color[i].addItem ("cyan");
color[i].addItem ("yellow");
color[i].addItem ("orange");
color[i].select (col);
panel.add (color[i]);
value[i] = new TextField (""+val);
panel.add (value[i]);
}
public boolean action (Event evt, Object obj)
{
if (pie == null) {
pie = (NFPiechartApp)
getAppletContext().getApplet("piechart");
}
if (pie == null) {
System.out.println ("Unable to access Piechart Applet");
return false;
}
String cmd = "Slices = ";
for (int i=0; i<4; i++) {
cmd += "("+value[i].getText()
+", "+color[i].getSelectedItem()
+", '"+label[i].getText()+"')";
if (i < 3) cmd += ", ";
else cmd += ";";
}
try {
pie.loadParams (cmd);
pie.loadParams ("Update");
} catch (Exception e) {
System.out.println (e.toString());
}
return true;
}
}