A choice is a pull-down list. It is also called as combo box. The choice menu is used to display a list of choices for the user to select from. The choice menu is selected by mouse click on the choice control, alist of options drops down.
To create a choice, first create a constructor, and the populate the choice by repeatedly calling addItem().
int getItemCount() - returns the number of items in the choice menu.
void select(int position) - select the item at the given position.
String getItem(int index) - return the text of a given item.
Example:
import java.applet.*;
import java.awt.*;
public class ChoiceDemo extends Applet
{
public void init()
{
Choice color=new Choice();
color.add("Red");
color.add("Green");
color.add("Blue");
add(new Label("normal appearance"));
add(color);
}
}
/*
* <applet code="ChoiceDemo.class" width=300 height=150>
* </applet>
*/
0 comments :
Post a Comment