new Choice()
A "Choice" is a form of pop-up menu. The entries in the menu are called "items". At any time, one item is considered the selected item. The choice usually appears in the display as a simple button with the currently selected item displayed. When the user depresses the mouse button while pointing at the choice, a menu displaying all the available items appears. The user can slide the mouse up and down the menu to point at the various items displayed. The item pointed to when the user releases the mouse becomes the new selected item.
Unlike most other user interface components, the creation of a Choice really requires more than just requesting a "new" Choice through a constructor method. To prepare a choice the applet must also add the desired items to the choice. This is done using a method called "addItem". This method expects a string parameter that can be displayed in the menu when the choice is selected. Thus, if "wavetype" is a variable associated with a choice, then an instruction of the form:
could be used to add the item "Sine" to the choice menu.wavetype.addItem("Sine");
void choiceMade(String itemChosen) { ... } void choiceMade(Choice target, String itemChosen) { ... }
When the user of an applet selects an item in a choice, the browser invokes the "choiceMade" method if the applet includes the definition of such a method. The "choiceMade" method must be defined to expect at least one parameter: the string identifying the choice selected. Optionally, "choiceMade" can be defined to also receive the choice that was changed as its first parameter.
somechoice.getSelectedItem() somechoice.select( itemName );
The method "getSelectedItem" can be used to determine which of a choice's items is currently selected. It returns the string describing the item in the choice menu.
The method "select" can be used to force the selected item in a choice to change without any action on the user's part. It expects as a parameter the string that identifies the item to be selected.