Choice menu. The choice menu is a more complex UI component than labels, buttons, or check boxes. Choice menus are pop-up (or pull-down) menus from which you can select an item. The menu then displays that choice on the screen. The function of a choice menu is the same across platforms, but its actual appearance may vary from platform to platform.

Note that choice menus can have only one item selected at a time. If you want to be able to choose multiple items from the menu, use a scrolling list instead (you'll learn more about scrolling lists later today, in the section "More UI Components").


import java.awt.*;

public class ChoiceTest extends java.applet.Applet {

    public void init() {
        Choice c = new Choice();

        c.addItem("Apples");
        c.addItem("Oranges");
        c.addItem("Strawberries");
        c.addItem("Blueberries");
        c.addItem("Bananas");

        add(c);
    }
}