//   Author: Brian C. Hoffman
//     File: TemplateApplet.java
// Abstract: This is an applet to demonstrate the use of swing GUI components by
//           performing additions.
//          
//  Revision History:      	Date (Due Date)	   Who	 Description
// -----------------------------------------------------------------------------
//		                    2/12/03            BCH	 Initial Release
//
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AdditionAppletFlow extends JApplet
{
    // declare three text fields and a button 
    JTextField numOne, numTwo, answer; 
    JButton sumButton;
    
    // initialize the applet and create the GUI
    public void init()
    {
        
        // create the text fields 
        numOne = new JTextField();
        numTwo = new JTextField();
        answer = new JTextField();
        
        // set the answer field to be uneditable and place default text in each field
        answer.setEditable(false);
        numOne.setText("Number1");
        numTwo.setText("Number2");
        answer.setText("Answer");
        
        // create the button and add an actionListener to it
        JButton sumButton = new JButton("Compute Sum");
        sumButton.addActionListener( new SumListener() );
        
        // add all the GUI components to the appler
        Container container = getContentPane();
        container.setLayout(new FlowLayout());
        container.add(numOne);
        container.add(numTwo);
        container.add(answer);
        container.add(sumButton);
    }
    
    // create the private action listener class
    private class SumListener implements ActionListener
    {
        public void actionPerformed(ActionEvent event)
        {
            int a, b, sum;
            a = Integer.parseInt(numOne.getText());
            b = Integer.parseInt(numTwo.getText());
            sum=a+b;
            answer.setText( Integer.toString(sum));
        }
    } // end SumListener
}