Count Number Of Items in a AWT Choice Or Combobox Example
- /*
- Count Number Of Items in a AWT Choice Or Combobox Example
- This java example shows how to count number of items of a choice or
- combobox using getItemCount method of AWT Choice class.
- */
- import java.applet.Applet;
- import java.awt.Choice;
- import java.awt.Graphics;
- /*
- <applet code="CountNumberOfItems" width=200 height=200>
- </applet>
- */
- public class CountNumberOfItems 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 count number of items in a choice or a combobox, use
- * int getItemCount() method of AWT Choice class.
- */
- int items = language.getItemCount();
- g.drawString("There are " + items + " items in a combobox", 10, 70);
- }
- }
Example Output




