import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
/**
 * A simple calculator that adds 2 numbers
 *
 */
 
public class HandleAction2 extends JFrame implements ActionListener 
{
    JTextField one    = new JTextField("0", 5);
    JLabel     plus   = new JLabel("+");
    JTextField two    = new JTextField("0", 5);
    JButton    equals = new JButton("Add");
    JLabel     result = new JLabel("???");

    public static void main(String[] arguments) 
    {
//      JFrame frame = new HandleAction2():         //I can create a variable of a parent           
                                                    //class, and hold a subclass object
        HandleAction2 frame = new HandleAction2();  //or a variable of the same class.  
    }

    public HandleAction2() 
    {
        setTitle("Add Two Numbers");
        setSize(300, 70);
        setDefaultCloseOperation(EXIT_ON_CLOSE);

        Container  window = getContentPane();       //get ref to ContentPane

        FlowLayout layout = new FlowLayout();       //create a FlowLayout
        window.setLayout(layout);                   //Flow the window using layout

        Color c = new Color(200,255,255);           //create an RGB color
        window.setBackground(c);                    //set the background color

        window.add(one);
        window.add(plus);
        window.add(two);
        window.add(equals);
        window.add(result);

        setVisible(true);                           //make window visible

        equals.addActionListener(this);             //add an event handler on button
    }

//---------------------------------------------------------------------------------
//  Event Handlers
//---------------------------------------------------------------------------------

    public void actionPerformed(ActionEvent evt) 
    {
        try {
            float value1 = Float.parseFloat(one.getText());
            float value2 = Float.parseFloat(two.getText());
            result.setText("" + (value1 + value2));
        }
        catch (NumberFormatException e) {
            result.setText("???");
        }
    }
}