// Draw a rectangle and give its area and perimeter based on parameters given, interactively, by user
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;

public class rectangle extends Applet
             implements ActionListener {
   Label LengthPrompt;     // prompt user to input first value
   TextField LengthInput;  // input first value here
   Label HeightPrompt;     // prompt user to input second value
   TextField HeightInput;  // input second value here  
   double LengthValue, HeightValue;  // store input values
   double Area, Perimeter;

   // setup the graphical user interface components
   // and initialize variables
   public void init()
   {
      LengthPrompt = new Label( "Type the length of the rectangle as a real number:" );
      add( LengthPrompt );  // put prompt on applet
      LengthInput = new TextField( 10 );
      add( LengthInput );   // put input on applet

      HeightPrompt =
         new Label( "Type the height of the rectangle as a real number and press Enter" );
      add( HeightPrompt );  // put prompt on applet

      HeightInput = new TextField( 10 );
      HeightInput.addActionListener( this );
      add( HeightInput );   // put input2 on applet
   }

   // display the results
   public void paint( Graphics g )
   {
	Area = LengthValue * HeightValue;
      g.drawString( "The area of the rectangle:" + Double.toString(Area), 70, 75 );

       Perimeter = 2 *(LengthValue + HeightValue);
         g.drawString( "Perimeter of rectangle is " + Perimeter, 100, 90 );

             g.drawString(  " Presenting... Your rectangle!" , 120, 105 );

     g.drawRect(250,250,(int) LengthValue, (int) HeightValue);
   }

   // process user's action on the HeightInput text field
   public void actionPerformed( ActionEvent e )
   {      
      LengthValue = Double.parseDouble( LengthInput.getText() );
      HeightValue = Double.parseDouble ( HeightInput.getText() );
      repaint();
   }
}
