// ChartTool.java - defines top level applet class for Bar Chart tutorial
//
// Code Developed for the Java Tutor article in Java Report Magazine
// Copyright (c) 1996 by Philip Meese, All Rights Reserved
//
import java.awt.*;      // references to Java packages we use
import java.awt.event.*;
import java.applet.Applet;

import BarChart;        // references to our classes
import NumericSet; 

//
// the ruling class
//
public class ChartTool extends Applet {

        // member data
        NumericSet      _set;
        BarChart        _barChart;
        TextField       _textField;
        GraphItButton   _button;
        final static int _width=200, _height=225;       // only works in appletviewer

        public void init(){
                _set=new NumericSet();                  // initialize member data
                resize(_width, _height);                // size the app window
                setLayout(new BorderLayout());          // create a layout mgr

                _textField=new TextField();             // input fld
                _textField.setText("12 24 15 76 54 15");// sample data for starters
                add("North", _textField);

                _barChart=new BarChart(_set, _width, 150);
                add("Center", _barChart);

                _button=new GraphItButton(this, "Graph It");
                add("South", _button);

                graphIt();                              // show sample data
        }
        // called to update graph
        public void graphIt(){
                String s=_textField.getText();          // get user input
                _set.setFromString(s);                  // reinitialize NumericSet obj
                _barChart.numericSet(_set);             // update the BarChart's NumericSet
        }       
} // end class ChartTool

//
// button to perform graphing
//
class GraphItButton extends Button implements ActionListener{
        ChartTool _app;

        // constructor
        public GraphItButton(ChartTool app_, String label_){
                setLabel(label_);
                _app=app_;
                addActionListener(this);
        }
        // this member function is called when the button is pressed
        public void  actionPerformed(ActionEvent e){
                _app.graphIt();
                }
} // end class GraphItButton

//eof
