Nice example from Oracle.
StringBuffer choices;
Four accessory choices provide for 16 different
combinations.
The "choices" StringBuffer contains the string that
indicates the current selection.You can change chars (c,g,h,t) on your symbols for process.Also,if you need postfix like "-MyAppArgument " you could add it,but it must be constant,because we need some fixed indexes to put our values depending on on/off toggle status of checkboxes.
choices = new StringBuffer("cght"); // change it to your postfix
---- //zero accessories
c--- //one accessory
-g--
--h-
---t
cg-- //two accessories
c-h-
c--t
-gh-
-g-t
--ht
-ght //three accessories
c-ht
cg-t
cgh-
cght //all accessories
You could add item listener on all of check boxes:
sampleCheckBox1.addItemListener(this);
sampleCheckBox2.addItemListener(this);
sampleCheckBox3.addItemListener(this);
sampleCheckBox4.addItemListener(this);
Then listen to them and change "choices":
public void itemStateChanged(ItemEvent e) {
int index = 0;
char c = '-';
Object source = e.getItemSelectable();
if (source == sampleCheckBox1) {
index = 0;
c = 'c';
} else if (source == sampleCheckBox2) {
index = 1;
c = 'g';
} else if (source == sampleCheckBox3) {
index = 2;
c = 'h';
} else if (source == sampleCheckBox4) {
index = 3;
c = 't';
}
//Now that we know which button was pushed, find out
//whether it was selected or deselected.
if (e.getStateChange() == ItemEvent.DESELECTED) {
c = '-';
}
//Apply the change to the string.
choices.setCharAt(index, c);
}
Also,if you had constant string just add it above main code,like:
final String = "-MyAppArgument ";