/*
Get Particular Item Of AWT Choice Or Combobox Example
This java example shows how to get a particular item from
choice or combobox using Java AWT Choice class.
*/
import java.applet.Applet;
import java.awt.Choice;
import java.awt.Graphics;
/*
<applet code="GetItemExample" width=200 height=200>
</applet>
*/
public class GetItemExample extends Applet{
Choice language = null;
public void init(){
//create choice or combobox
language = new Choice();
//add items to the choice
language.add("Java");
language.add("C++");
language.add("VB");
language.add("Perl");
//add choice or combobox
add(language);
}
public void paint(Graphics g){
/*
* To get a particular item of a choice or a combobox, use
* String getItem(int index)
* method of AWT Choice class.
*/
g.drawString(language.getItem(2) + " is at index 2", 10, 70);
}
}
Example Output

Bookmark/Search this post with: