Which event type does JVM generate when a user clicks a radio button? Is it an action event or an item event?

183 Views Asked by At

I am fairly new to swing components. However, I have seen many examples where a radio button implements actionListener as well as itemListener. Which one is the correct way of handling events in such a case?

1

There are 1 best solutions below

0
Andrew Thompson On

Which event type does JVM generate when a user clicks a radio button? Is it an action event or an item event?

It depends which listener(s) has(/have) been attached to the radio buttons! E.G. Either or both of AbstractButton.addActionListener(ActionListener) / addItemListener(ItemListener).

Aside: for this I'd recommend an ActionListener.
The ItemListener will produce two events when a button in a ButtonGroup is selected. One of the events is for the item which just got deselected.