// Addition program import java.applet.Applet; import java.awt.*; // import the java.awt package import java.awt.event.*; // import the java.awt.event package public class Addition extends Applet implements ActionListener { Label prompt; // message that prompts user to input TextField input; // input values are entered here int number; // variable that stores input value int sum; // variable that stores sum of integers // setup the graphical user interface components // and initialize variables public void init() { prompt = new Label( "Enter integer and press Enter:" ); add( prompt ); // put prompt on applet input = new TextField( 10 ); add( input ); // put input TextField on applet sum = 0; // set sum to 0 // "this" applet handles action events for TextField input input.addActionListener( this ); } // process user's action in TextField input public void actionPerformed( ActionEvent e ) { // get the number and convert it to an integer number = Integer.parseInt( e.getActionCommand() ); sum = sum + number; // add number to sum input.setText( "" ); // clear data entry field showStatus( Integer.toString( sum ) ); // display sum } }