//  AreaSimpleApplet.java
//  Calculates the area of a rectangle given two integer sides
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class AreaSimpleApplet extends JApplet implements ActionListener {
        // instance variables
        Container c;
        JLabel lenPrompt, widPrompt, areaResult;
        JTextField length, width, area;
        int l, w, a;

        public void init( ) {
                // create container c to hold the components
                c = getContentPane( );
                c.setLayout( new FlowLayout( ) );

                // create GUI components and add to container
                lenPrompt = new JLabel( "Enter the length:" );
                c.add( lenPrompt );
                length = new JTextField( 10 );
                length.addActionListener( this );
                c.add( length );
                widPrompt = new JLabel( "Enter the width:" );
                c.add( widPrompt );
                width = new JTextField( 10 );
                width.addActionListener( this );
                c.add( width );
                areaResult = new JLabel( "Area:" );
                c.add( areaResult );
                area = new JTextField( 10 );
                c.add( area );
        }

        public void actionPerformed( ActionEvent e ) {
                // convert inputs to integers
                l = Integer.parseInt( length.getText( ) );
                w = Integer.parseInt( width.getText( ) );
                // calculate area and display in text field
                a = l * w;
                area.setText( Integer.toString( a ) );
        }
}