import java.awt.*;
import java.awt.event.*;
/** 
 * This class demonstrates in a simple way the use of an ActionListener interface
 * By implementing ActionListener, AL becomes an ActionListener and can be added
 * to components to listen for actions related to them. 
 * 
 * @author Nancy Harris
 *
 */
public class ExpressionsGUI extends Frame implements WindowListener, ActionListener 
{
        private TextField expression;
        private TextField result; 
        private Button button;

        
        
        /**
         * The constructor takes in a title and constructs all of the components
         * of this frame.
         * 
         * @param title The title for this window.
         */
        public ExpressionsGUI(String title) 
        {
                // This line sends the title to the "Frame" from which AI 
                // is constructed.
                super(title);
                
                // FlowLayout is the default.
                setLayout(new GridLayout(3, 1));
                
                // This will listen for the close action on the window.
                addWindowListener(this);
                
                // Buttons are components that can be "clicked";
                button = new Button("Submit");
                
                // Create the text fields
                expression = new TextField(20);
                result = new TextField(20);
                result.setText( "Enter your expression above" );
                result.setEditable(false);  // for results only
                
                add(expression);
                add(result);
                add(button);
                
                // This step is adding this object as an ActionListener 
                // to the button.
                button.addActionListener(this);
        }

        /**
         * Required by the interface, this actionPerformed will increment
         * get the text from the expressions field, create an ExpressionParser
         * and then get the result from the isExpression method. 
         * If the result is true, set the result field to "Correct".
         * If the result if false, set the result field background to red and 
         * print the String "Incorrect".
         */
        public void actionPerformed(ActionEvent e) 
        {
            // write me
        }

        /**
         * This closes the window and ends the program.
         */
        public void windowClosing(WindowEvent e) 
        {
                dispose();
                System.exit(0);
        }

        /**
         * While these methods are "required" by the WindowListener
         * interface, they are not needed in this application. 
         * These "stubs" serve as implementations for the WindowListener
         * interface.
         */
        public void windowOpened(WindowEvent e) {}
        public void windowActivated(WindowEvent e) {}
        public void windowIconified(WindowEvent e) {}
        public void windowDeiconified(WindowEvent e) {}
        public void windowDeactivated(WindowEvent e) {}
        public void windowClosed(WindowEvent e) {}

}
