I am writing a Java App that has multiple items available to test. However -- due to HW limitations, I can only test 4 devices in parallel. I was wondering -- in genera -- how can I get Java to limit the number of selected items to only four (no matter which ones are picked)? I am reading through the Java docs and I can't seem to find the answer to that.
I am fairly new to Java -- so please forgive my ignorance. I just need a clue as to where/how to start.
How do I limit the number of check boxes selected in Java?
If you're using Swing, start with creating an array of JCheckBox[] and fill it with checkboxes. Create then ChangeListener and global variable with amount of checked checkboxes. Add this listener to all of checkboxes. In ChangeListener's stateChanged()
method increase or decrease your global variable by 1. If variable reach four, disable all of checkboxes with setEnabled(false) except those which are checked. When you'll decrease your variable from 4 to 3, set them to enabled.
This is good example about ChangeListener: http://www.java2s.com/Code/Java/Event/CheckBoxItemListener.htm