How to code which CheckBoxMenuItem is selected in Java?
Posted
by waterfallrain
on Stack Overflow
See other posts from Stack Overflow
or by waterfallrain
Published on 2010-03-28T18:42:07Z
Indexed on
2010/03/28
18:53 UTC
Read the original article
Hit count: 197
java
I am trying to add a method which takes the menu selection and passes it to a variable. In this case I would like to take "7" and insert that into the year variable if that is what is selected from teh checkboxmenu. So far have search the internet and sun site with no clear example on how to differentiate the menu items. Any suggestions would be appreciated thanks.
cbMenuItem = new JCheckBoxMenuItem("7 year"); cbMenuItem.setMnemonic(KeyEvent.VK_H); cbMenuItem.addItemListener(this); menu.add(cbMenuItem);
cbMenuItem = new JCheckBoxMenuItem("15 year");
cbMenuItem.setMnemonic(KeyEvent.VK_S);
cbMenuItem.addItemListener(this);
menu.add(cbMenuItem);
© Stack Overflow or respective owner