// InnerClassDemo.java
// Uses first day AreaSimple.java but with anonymous inner classes to handle events
//  Calculates the area of a rectangle given two integer sides
//  APPLET CODE="InnerClassDemo" HEIGHT=200 WIDTH=135
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

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

	public void init( ) {
		l = 0;
		w = 0;

		// 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( 
			new ActionListener( ) {
				public void actionPerformed( ActionEvent e ) {
					l = Integer.parseInt( length.getText( ) );
					w = Integer.parseInt( width.getText( ) );
					compArea( );
				}
			}
		);
		c.add( length );

		widPrompt = new JLabel( "Enter the width:" );
		c.add( widPrompt );
		width = new JTextField( 10 );
		width.addActionListener( 	
			new ActionListener( ) {
				public void actionPerformed( ActionEvent e ) {
					l = Integer.parseInt( length.getText( ) );
					w = Integer.parseInt( width.getText( ) );
					compArea( );
				}
			}
		);
		c.add( width );

		areaResult = new JLabel( "Area:" );
		c.add( areaResult );
		area = new JTextField( 10 );
		c.add( area );
	}

	public void compArea( ) {
		a = l * w;
		area.setText( Integer.toString( a ) );
	}
}