//RectangleAppletInit.java //rectangle applet that uses init only import java.awt.*; import javax.swing.*; public class RectangleAppletInit extends JApplet { //applet can have paint and/or init. //init runs before paint. can use JOptionPane in it but not in paint. public void init() { int width, height; int perimeter, area; String input; input = JOptionPane.showInputDialog( "Enter width of rectangle" ); width = Integer.parseInt( input ); input = JOptionPane.showInputDialog( "Enter height of rectangle" ); height = Integer.parseInt( input ); perimeter = 2 * width + 2 * height; area = width * height; JOptionPane.showMessageDialog(null, "Area=" + area + "\n" + "Perimeter=" + perimeter ); } }