private void commercialButtonClicked(String command){
  int length=Integer.parseInt(command);
  JToggleButton button=commercialButtons.get(length);
  if (button.isSelected()) {
    if (scheduledCommercialTime == 0) {
      runCommercial(length);
    }
 else {
      scheduledCommercialLength=length;
      update();
    }
  }
 else {
    scheduledCommercialTime=0;
    setCommercialResult("Canceled scheduled commercial.");
  }
}

private void commercialButtonClicked ( String command ) { int length = Integer . parseInt ( command ) ; JToggleButton button = commercialButtons . get ( length ) ; if ( button . isSelected ( ) ) { if ( scheduledCommercialTime == 0 ) { runCommercial ( length ) ; } else { scheduledCommercialLength = length ; update ( ) ; } } else { scheduledCommercialTime = 0 ; setCommercialResult ( "Canceled scheduled commercial." ) ; } }
one of the commercial buttons was clicked . find out which one by the action command and check if it was selected / unselected .
