// 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 javax.swing.*;

import BarChart;        // references to our classes
import NumericSet; 

//
// the ruling class
//
public class ChartTool extends JApplet {

        // member data
        NumericSet      _set;
        BarChart        _barChart;
        JTextField       _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
                getContentPane().setLayout(new BorderLayout());          // create a layout mgr

                _textField=new JTextField();             // input fld
                _textField.setText("12 24 15 76 54 15");// sample data for starters
                getContentPane().add("North", _textField);

                _barChart=new BarChart(_set, _width, 150);
                getContentPane().add("Center", _barChart);

                _button=new GraphItButton(this, "Graph It");
                getContentPane().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 JButton 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
