// Addition program
import java.awt.*;    // import the java.awt package
import java.awt.event.*;   
import java.applet.Applet;

public class SimpleCalc extends Applet implements ActionListener {
   Label prompt;      // prompt user to input
   TextField input1, input2, result;   // input values here
   int number1, number2;        // store input value
   int sum;           // store sum of integers
   Button plusButton;

   // setup the graphical user interface components
   // and initialize variables
   public void init()
   {
      prompt = new Label( "Enter integers and press button:" );
      input1 = new TextField( 10 );     
      input2 = new TextField( 10 );     
      result = new TextField( 10 );     
	  result.setEditable(false);
	  plusButton =new Button("+");
      add( prompt );  // put prompt on applet 
      add( input1 );   // put input on applet
      add( input2 );   // put input on applet
	  add(plusButton);
	  add(result);
      sum = 0;        // set sum to 0
	  plusButton.addActionListener(this);
   }

   // process user's action on the input text field
   public void actionPerformed( ActionEvent e )
   {
	  String symbol = e.getActionCommand();
      number1 = Integer.parseInt( input1.getText() ); // get number1 
      number2 = Integer.parseInt( input2.getText() ); // get number2
	  if ( symbol.equals("+") )
		sum = number1 + number2;
      input1.setText( "" );  // clear data entry field
      input2.setText( "" );  // clear data entry field
      result.setText( number1+symbol+number2+"="+Integer.toString( sum ) );  // show result
   }
}
