// Program 15.5: A Choice Menu import java.applet.Applet; import java.awt.Choice; import java.awt.Label; import java.awt.Event; import java.awt.TextField; import java.util.StringTokenizer; public class PizzaSize extends Applet { /* You'll need access to t from the handleChoice method so make it a member variable. */ TextField t; public void init() { add(new Label("What size pizza would you like?", Label.CENTER)); Choice ch = new Choice(); ch.addItem("6 inches"); ch.addItem("9 inches"); ch.addItem("12 inches"); ch.addItem("16 inches"); ch.addItem("20 inches"); add(ch); t = new TextField(12); t.setEditable(false); add(t); } public boolean action(Event e, Object o) { if (e.target instanceof Choice) { handleChoice((Choice) e.target); } return true; } private void handleChoice(Choice c) { String s = c.getSelectedItem(); StringTokenizer st = new StringTokenizer(s); int size = Integer.parseInt(st.nextToken()); float price = 2.0f; switch (size) { case 6: price = 2.0f; break; case 9: price = 6.0f; break; case 12: price = 9.0f; break; case 16: price = 12.0f; break; case 20: price = 16.0f; break; } t.setText(String.valueOf(price)); } }