A major vision of this class is to encourage its students to become good programmers.
The class provides a setting where people who like to program in the Java language can meet and talk with other like-minded programmers. Come join us! You won't regret it! You owe it to yourself!
[email protected]
Contact:
[email protected]
Source Code
// 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( "Type a whole number and press Enter please:" );
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() );
System.out.println("Hello ma! - e.getActionCommand() yields: " + e.getActionCommand());
number = Integer.parseInt( input.getText() );
sum = sum + number; // add number to sum
input.setText( "" ); // clear data entry field
showStatus( Integer.toString( sum ) ); // display sum
}
}