Do you think IIT Guwahati certified course can help you in your career?
No
Introduction
The choice becomes one of the essential aspects of programming when choosing one of them based on the user's choice. The choice control displays a popup menu of options. The top of the menu shows the selected option. In this article, we shall be learning about AWT Choice in Java.
The Java Abstract Window Toolkit includes the Choice class (AWT). The Choice class displays a popup menu to the user, from which the user can pick an item. The selected item is shown at the top of the list. The Choice class inherits the Component class.
Syntax
public class Choice extends Component implements ItemSelectable, Accessible
You can also try this code with Online Java Compiler
This section will look for a few codes related to AWT Choice.
Code 1
import java.awt.*;
import javax.swing.*;
public class AWTChoiceExample {
static Choice c;
static JFrame f;
public static void main(String args[])
{
f = new JFrame("choice");
JPanel p = new JPanel();
c = new Choice();
c.add("Mutiur");
c.add("Yawar");
c.add("Saalim");
p.add(c);
f.add(p);
f.show();
f.setSize(300, 300);
}
}
You can also try this code with Online Java Compiler
The Java Abstract Window Toolkit includes the Choice class (AWT). The Choice class displays a popup menu to the user, from which the user can pick an item. The selected item is shown at the top of the list. The Choice class inherits the Component class.
What are AWT classes in Java?
TextField, Label, TextArea, RadioButton, CheckBox, Choice, List, and other AWT API classes are available in java. awt package.
How to show the popup menu of choices in Java AWT?
The Choice class object is used to display a popup menu of options. A user-selected option appears at the top of a menu.
Conclusion
In this article, we have extensively discussed the AWT Choice. We have briefly introduced the topic along with its methods and constructors. We also have discussed a few codes with their output and solution, which explains the purpose of this blog.
If you want to explore more about AWT, visit here.