Home | » | Java | » | Advance Java | » | Java AWT (Abstract Window ToolKit) | » | Choice Controls |
---|
These are same as a Simple List Which contains a Series of Choices and one can select an item from that list . But theses Choice Lists provides selection of only one item from a list and to add various optisons we have to use the add Method of Lists like this.
Ch.add("Red");// add : Name of Method to Add Options in List.
Ch.add("Green");
Ch.add("Yellow");
add(Ch);
The first statement creates an object of the Choice class.
The second and third statement adds two items to the Choice list.
The following example displays a dropdown Choice list in applet ChoiceTest.
The above code will be stored in the file called ChoiceTest.java, which on compilation will crate a class file called ChoiceTest.class. Now compiple this file using below commands in the DOS mode:
C:\>jdk1.4\bin>javac ChoiceTest.java
C:\>jdk1.4\bin>appletviewer ChoiceTest.java
|
||
Download Complete Program |
Methods of the Chioce Object:
GetItem(int) | Returns the string item at the given position(items inside a choice begins at 0,as in arrays). |
GetSelectedIndex() | Returns the index position of the item that is selected |
GetSelectedItem() | Returns the currently selected item as a string |
Select(int) | Selects the item at the given position. |
Select(String) | Selects the item with the given string. |
AWT Controls
Label | Buttons | Check Boxes | Radio Buttons | |
Choice Controls | TextFields & Password | TextAreas | Scrolling Lists | Scrollbars |
No comments:
Post a Comment