import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class TwoAdd extends JApplet 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 void init() {
        TwoAdd applet = new TwoAdd();
    }

    public TwoAdd() {

//      setTitle("Add Two Numbers");                //invalid for Applet
//      setSize(300, 70);                           //invalid for applet
//      setDefaultCloseOperation(EXIT_ON_CLOSE);    //invalid for applet

        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
    }

    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("???");
            showStatus("Bad Number Entered");   //display in browser status line
        }
    }
}