This code gets how many checkboxes (nchecked) are selected. It works when more than 2 boxes are selected, but no warning is outputted when I have no checkboxes selected. What should be different?
Here's the code that gets the checkboxes
private int getCheckBoxes(){
int count = 0;
for (int i = 0; i < checkBoxes.size(); i++){
if (checkBoxes.get(i).isSelected()) {
count++;
}
}
return count;
}
private int getIndex(String cityName) {
return cities.indexOf(cityName);
}
//Here is the code that I'm putting out my warning
private void handleCitySelection (int index) {
if (checkBoxes.get(index).isSelected())
{
int nchecked = getCheckBoxes();
if (nchecked <= 0)
{
outputDistance.append("Please Select 2 Cities");
}
if(nchecked >= 3)
{
checkBoxes.get(index).setSelected(false);
}
else
if (nchecked == 1) {
city1 = index;
}
else
{
city2 = index;
}
}
}
Also behind each checkbox is:
handleCitySelection(getIndex(evt.getActionCommand()));
Thanks in advance!!
Aucun commentaire:
Enregistrer un commentaire