I am making a simple currency convertor which takes the initial value in a JTextField then the user clicks the JCheckBox corresponding to their desired currency, the converted value will then be displayed in another JTextField. Basically i would like to know is there any way of assigning a value to a checked JCheckBoxi 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.
Think it’d be easier if you assign an
action-listenerto yourJCheckBoxand make the conversion on trigger of this event. To check is aJCheckBoxis checked or not you can use theisSelected()methodEDIT
Actually i think you need to use
JRadioButton‘s in aButtonGroupfor 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