How to obtain data from a checkbox?

0

How you can obtain data by selecting a checkbox, as shown in the image:

When entering a salary, I get its value from the field and when I select "AFP" I can multiply the value obtained from salary with 0.10 which is the value of the AFP, in the same way the others, how would that goal achieve?

    
asked by Innuendo 20.08.2018 в 22:39
source

1 answer

0

To check if a CheckBox is selected, the following method is used

tuCheckBox.isSelected();

This method returns a boolean that is false if it has not been selected or true if the checkbox is selected. You just have to check the value of this boolean inside your ActionListener that runs once the button is clicked. For example:

if(AFP.isSelected()){
    //Aqui realizas tus calculos
}

I do not know if you already know, but if only one JCheckBox can be selected at the same time, you should use a ButtonGroup , this ensures that only one button can be selected at a time.

    
answered by 21.08.2018 в 08:05