vendredi 22 avril 2016

Java GUI checkbox control logic needed

I have to complete a Java 7/8 project for a client with a requirement regarding four (4) checkboxes on a Java GUI form. I would rather not use the latest Java 8 feature, if there exists such a new feature, and stick with what works for older Java versions, as well.

I am having trouble with the logic regarding how the checkboxes are supposed to work together, and I am hoping someone might be able to help me solve this. I do not have trouble selecting and unselecting a checkbox, only in the logic governing all four, as such:

Consider the checkboxes named: userCheckBoxA, userCheckBoxB, userCheckBoxC, and userCheckBoxD

At this point, neither is selected on GUI startup, but I am willing to change that to selecting CheckBoxA at startup, if that helps the logic here.

What I need to accomplish is if CheckBoxA is selected, then the other three are cleared, and if either B, C, or D is selected, then A is cleared. As it is supposed to work, B, C, or D might be selected after A is selected, which means that A selected would make no sense. If A is selected, then B, C, or D selected would make no sense.

I am currently using a public class ActionHandler implementing ActionListener with each checkbox registered with (eg.) userCheckBoxA.addActionListener( checkBoxListener) The checkboxes are in a panel, but (currently) they are not grouped in another manner.

With every attempt that I have made, I have (basically) created an infinite loop (of sorts) when certain checkboxes are selected in a certain order.

I am hoping that someone with more experience that I can look this over and solve this logic puzzle for me.




Aucun commentaire:

Enregistrer un commentaire