// SimpleMenu.java // Illustrates the switch statement import java.awt.*; import java.applet.*; public class SimpleMenu extends Applet { TextField inTF = new TextField(3); Label output = new Label("", Label.CENTER); public void init() { setLayout(new BorderLayout()); Panel p = new Panel(); Label l = new Label("Choose 1) Tofu or 2) Twinkies. Press ENTER"); p.add(l); p.add(inTF); add ("North", p); add ("South", output); } public boolean action(Event e, Object o) { String choice = inTF.getText(); if (choice.length() > 0) { char ch = choice.charAt(0); switch (ch) { case '1': output.setText("Here's your tasty TOFU"); break; case '2': output.setText("Here's your yummy TWINKIE"); break; default: output.setText("Do you see " + choice + " on the menu?"); break; } } return true; } }