Technical Support
Discussion Forum
Online Training
Read About Java
Java In-Depth
Product Discounts
Membership Information

Java Cup Logo

JDC Home Page


Top
Back
Next
Online Training
shadowSearchFAQFeedback

Choice

Choice objects are pop-up menus. The visible label of the Choice object is the currently selected entry of the Choice. Items are added to the Choice object via the Choice addItem method.



Corresponding source code:

import java.applet.*;
import java.awt.*;
public class ChoiceWidget extends Applet {
    public void init()
    {
        Choice rgb = new Choice();
        rgb.addItem("Red");
        rgb.addItem("Green");
        rgb.addItem("Blue");
        add(rgb);
    }
}

Methods:

  • public int getSelectedIndex()
    Which item was selected?
  • public String getSelectedItem()
    Which item was selected?
  • public void select(String str)
    Selects item str.

Related exercises: