I would like to have 6 checkboxes, and do some stuff after a botton is pressed do you have an example?
Also can an array of checkboxes be used?
I want to avoid:<
You can do something like this:
List<Checkbox> checkboxes = new ArrayList<Checkbox>();
String labels[] = {"A", "B", "C", "D", "E", "F"};
for (int i = 0; i < labels.length; i++) {
Checkbox checkbox = new Checkbox(labels[i]);
checkboxes.add(checkbox); //for further use you add it to the list
}
And then the List use it in your ActionListener to reference the checkboxes. You can also use an array if you like.
Yes, have an array of JCheckBox
, example:
JCheckBox[] checkBoxes = {new JCheckBox("1"), new JCheckBox("2"), new JCheckBox("3"), new JCheckBox("4"), new JCheckBox("5"), new JCheckBox("6")};
or
JCheckBox[] checkBoxes = new JCheckBox[6];
Then you will have to iterate through checkBoxes.length
and instantiate it (if you didn't) and add your listener through addItemListener()
and finally adding each checkbox to your JFrame
.
I hope this helps.