In this section, you will learn about handling item events in java. This demonstrates that the event generated when you select an item from the group of the items.
This program demonstrates how the item events is handled. You can perform several operations according to the selecting of items from the item group.
Here, you will see the handling item event through the given program in which, a combo box and a text area have been taken. Items of the combo box are as follows : Red, Green, Blue. If you select an item from the combo box then the message with the item name will be displayed in the text area.
This is the constructor of the Choice class which creates combo box.
This is the ItemEvent class which indicates an event on selecting or deselecting items from the item group. This event is passed by ItemListener object. The generated event is passed to all ItemListener objects which is registered to receive such types of event. This is done using the addItemListener() method of the object.
This is the method of the ItemEvent class which returns the value of the selected or deselected item.
Here is the code of program :
Recommend the tutorial