ActionListener and ItemListener

J

Jenny

Hi Friends,

First, for JRadioButton and JCheckBox, is ActionListener enough for
all the situations? I really cannot find a case where I must use
ItemListener instead of ActionListener interface.

Second, in the Class ItemEvent, what is the difference between the
getItemSelectable() and the getItem() methods.

Thanks a lot!
 
C

Christian Kaufhold

Jenny said:
First, for JRadioButton and JCheckBox, is ActionListener enough for
all the situations? I really cannot find a case where I must use
ItemListener instead of ActionListener interface.

If you want to know whenever the selection changes, no matter whether
programmatically or by the user (provided ItemEvents remain implemented
in contradiction to the broken specification).

However, both specification and implementations of ItemSelectable or
so broken that I would not recommend to use them. Instead of Item-
Listener one can just use ChangeListener (except the AWT components)
to find out whenever the selection changes.

Second, in the Class ItemEvent, what is the difference between the
getItemSelectable() and the getItem() methods.

'itemSelectable' is the ItemSelectable, which may have one or more
items selected. The 'item' is that item which became (de-)selected.
For example, for JComboBox, the ItemSelectable is the combobox itself,
the item is the 'selectedItem' (or the object that was 'selectedItem'.


Christian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top