I am coding a game in java swing in which the user has to click on check boxes. The number of check boxes selected increases with each selection but for some reason also increases whenever you unselect the check box.
choice[0]=5; // assigns a finite number for user's choice to improve program efficiency
select++;
jTextField2.setText(String.valueOf(select)); // prints the number of checkboxes selected
if (jCheckBox1.setSelected(true))
{
select--;
}
if(select==5) // disables all check boxes when 5 are
selected
{
jCheckBox1.setEnabled(false);
jCheckBox2.setEnabled(false);
jCheckBox3.setEnabled(false);
jCheckBox4.setEnabled(false);
jCheckBox5.setEnabled(false);
jCheckBox6.setEnabled(false);
jCheckBox7.setEnabled(false);
jCheckBox8.setEnabled(false);
jCheckBox9.setEnabled(false);
jCheckBox10.setEnabled(false);
jCheckBox11.setEnabled(false);
jCheckBox12.setEnabled(false);
jCheckBox13.setEnabled(false);
jCheckBox14.setEnabled(false);
jCheckBox15.setEnabled(false);
jLabel6.setText("Great! Now click on the 'Found you!' button to continue. "); //restricts user from selecting more than 5 boxes
//and prompts them to click on 'Found you ' button.
}
The line of code if (jCheckBox1.setSelected(true))
gives me the error "void cannot be converted to boolean". Can someone please help me improve the code in a way that decreases the value of "select" whenever a checkbox is unselected.
Thanks.