Using JCheckBoxMenuItem

I want to add some actions to the check box menu item, but I don't know how should it be done, or how the code will look like, I tried implementing ItemSelectable but it doesn't work, so should I add an action for each item of what.

Here the items are created

if(i == 0 || i == 4)

allAgents[i] =new JCheckBoxMenuItem("System Image Agent "+(i==0?1:2));

.

.

and here the action method

publicvoid itemStateChanged(ItemEvent e)

{

Object eventSource = e.getItemSelectable();

// testing

System.out.println("Method entered");

for(int i=0;i<8;i++)

{

if(eventSource == allAgents[i])

{

//testing

System.out.println("Agent "+i);

//allAgentsStatus[i] = 0;

if(allAgents[i].isSelected())

allAgentsStatus[i] = 1;

else

{

allAgentsStatus[i] = 0;

//testing

System.out.println("Agent "+i+" is not selected");

}

}

}

}

[1740 byte] By [Rami_Magdia] at [2007-11-27 6:27:59]
# 1
Have you registered the ItemListener at all your JCheckBoxMenuItem instances?
quittea at 2007-7-12 17:50:14 > top of Java-index,Java Essentials,Java Programming...
# 2
how should I do it
Rami_Magdia at 2007-7-12 17:50:14 > top of Java-index,Java Essentials,Java Programming...
# 3
http://java.sun.com/docs/books/tutorial/uiswing/events/intro.html
quittea at 2007-7-12 17:50:14 > top of Java-index,Java Essentials,Java Programming...
# 4
In the future, Swing related questions should be posted in the Swing forum.Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/progress.html]How to Use Menus[/url] for a working example.
camickra at 2007-7-12 17:50:14 > top of Java-index,Java Essentials,Java Programming...