// AreaJOptionPaneApplet.java 
// Calculates the area of a rectangle given two integer sides 
// Uses JOptionPane to prompt for inputs 
// import java.awt.*;
import javax.swing.*; 

public class AreaJOptionPaneApplet extends JApplet{ 
        // instance variables 
        String widString, hgtString; 
        int w, h, a; 

        public void init( ) { 
                // read in width as a String 
                widString = JOptionPane.showInputDialog( "Enter the width as an integer" ); 
                // convert the String to an integer
                w = Integer.parseInt( widString ); 
                // read in height as a String 
                hgtString = JOptionPane.showInputDialog( "Enter the height as an integer" ); 
                // convert the String to an integer 
                h = Integer.parseInt( hgtString ); 
                // compute the area 
                a = w * h;
        } 

        public void paint( Graphics g ) { 
                // display the  area as a String 
                g.drawString( "The area of the square equals " + a, 25,25 ); 
                // draw the rectangle scaled by a factor of 10 for looks 
                g.fillRect( 25, 100, 10 * w, 10 * h );
        }
}