Darren Burgess Darren Burgess - 1 year ago 90
Java Question

how to assign value to a checked JChechbox?

I am making a simple currency convertor which takes the initial value in a

then the user clicks the
corresponding to their desired currency, the converted value will then be displayed in another
. Basically i would like to know is there any way of assigning a value to a checked
i have looked around and cannot find a clear answer to this, any help would be appreciated.

For example if the current conversion rate from Sterling to euro is 1.12244 this value would be assigned when the JCheckBox is checked, so the the original value would be multiplied by the conversion rate.

Answer Source

Think it'd be easier if you assign an action-listener to your JCheckBox and make the conversion on trigger of this event. To check is a JCheckBox is checked or not you can use the isSelected() method


Actually i think you need to use JRadioButton's in a ButtonGroup for this, as if you are using a checkbox then there is a chance that more than one is selected. Here is an example of how to do use ButtonGroup and trigger action on the radio button

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download