// An Applet program take from Deitel & Deitel, "Java How to Program", 
// pp. 211 - 213
/** An Applet prgram that draws lines, rectangles, or ovals depending on 
 user's choice; the applet is run with the following html file:
    <html>
      <applet code = "SwitchTest.class" width = "260" height = "260">
      </applet>
    </html>
  This html file (say, named "SwitchTest.html") can be run as follows:
    appletviewer SwitchTest.html
  or it can be opened from a web browser such as IE or Netscape
  (Nov. 22, 2001)
*/

import java.awt.Graphics;  // Java core package
import javax.swing.*;  // Java extension packages

public class SwitchTest extends JApplet {
  int choice;  // user's choice for drawing 

  /** initialize applet by prompting user for choice */
  public void init() {
    // user input
    String input = JOptionPane.showInputDialog(
                           "Enter 1 to draw lines\n" +
                           "Enter 2 to draw rectangles\n" +
                           "Enter 3 to draw ovals\n");

    choice = Integer.parseInt(input);
  }

  /** draw shapes on applet's background */
  public void paint(Graphics g) {
    super.paint(g);  // call inherited paint() method
    // draw a chosen shape 10 times
    for (int i = 0; i < 10; i++) 
      switch (choice) {
        case 1:  g.drawLine(10, 10, 250, 10 + i * 10);
                 break;
        case 2:  g.drawRect(10 + i * 10, 10 + i * 10,
                                      50 + i * 10, 50 + i * 10);
                 break;
        case 3:  g.drawOval(10 + i * 10, 10 + i * 10,
                                      50 + i * 10, 50 + i * 10);
                 break;
        default:  g.drawString("Invalid value entered",
                                        10, 20 + i * 15);
      }  // end of switch

  }  // end of paint()
}  // end of class SwitchTest


