Home Java Example Java Awt Choice Option (Combo) In Java



Choice Option (Combo) In Java
Posted on: April 17, 2007 at 12:00 AM
In this section, you will learn how to create Drop-Down List by using Java AWT package.

Choice Option (Combo) In Java

     

In this section, you will learn how to create Drop-Down List by using Java AWT package.

Here, you will see in the output of the program that is given ahead for the illustration of the topic. This tells you about the procedure of constructing a drop down list in java by using java awt.

There is a program with complete java code that can be copied and paste in your java application for creating a combo box with some items, has been explained here:

Program Description:

Following program uses the Choice class for creating a Drop-Down List. This program is also using add() method of the Choice class for add item to the list like "ROSE", "INDIA" and "WELCOME".

Choice():- This is the default constructor of Choice class. This creates simply a drop-down list.

Here is the code of this program:

import java.awt.*;
import java.awt.event.*;
public class ChoiceOptionExample{
  public static void main(String[] args) {
  Frame frame=new Frame("Choice");
  Label label=new Label("What is your Choice:");
  Choice choice=new Choice();
  frame.add(label);
  frame.add(choice);
  choice.add("ROSE");
  choice.add("INDIA");
  choice.add("WELCOME");
  frame.setLayout(new FlowLayout());
  frame.setSize(250,150);
  frame.setVisible(true);
  frame.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent e){
  System.exit(0);
   }
  });
  }
}

Output this program:

Download this Example:

Related Tags for Choice Option (Combo) In Java:
javaclistiostructoutputconstawtusingthisforprogramtoramdroppicproctopeilprocedurelsliputceinmheadouttrjadpiillustrationprododownseeatratioishalliveaduconsstrwtvassrocthavstabatihatpronogro


More Tutorials from this section

Ask Questions?    Discuss: Choice Option (Combo) In Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.