dimanche 1 février 2015

How to unselect and undo with checkboxes using Java Swing?

I have a checkbox, when the checkbox is selected I want to add int 2 to my total. Then I want to be able to unselect it and then subtract int 2 to my total.


At the moment, I cant unselect and subtract 2.


Also, my checkbox is in a button group so I need to use clearSelection() as a solution to deselect.


The code I currently have for this is (which isn't work too well):



monTill4ChckBox.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

if(monTill4ChckBox.isSelected()){

mondayCost= mondayCost + 2;
}
else{
mondayCost= mondayCost - 2;
monAftergroup.clearSelection();
}




Aucun commentaire:

Enregistrer un commentaire