The text you are reading is from this HTML document "Addition2.html"

Next to display is the Applet and  the Applet tag defines the width and height of

the applet's area:  300 wide & 155 high it shows here on the page in white -->

This text is from the HTML document again.

The applet tag used in this HTML document looks like this:

<APPLET
CODEBASE="." CODE="Addition2.class" 
ALIGN=MIDDLE 
VSPACE=5 
WIDTH=300 HEIGHT=155 
archive="Addition2.jar">
</APPLET> 

You can think of the white applet area (300*155) as the graphics object that the browser passes into
the Applet's paint method: public void paint (Graphics g) {...

The entire applet code follows - this java text file is compiled into Addition2.class
// Addition program (modified fig 1_06, Deitel edition 2) // Modified to give proper output in the applet screen import java.applet.Applet; import java.awt.*; // import the java.awt package import java.awt.event.*; // import the java.awt.event package public class Addition2 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 ); } public void paint (Graphics g) { g.drawString("The Running Total is " + sum, 40,40); } // 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 repaint(); // Force paint to be invoked } }



22-sept-09