// Initialize the buttons ArrayList because there the program messes up if the voter doesn't vote // for anything, the buttons array // will be null. public void initializeButtons() { FileIO nullFile = new FileIO(); // need to create this just to gain access to the filename of the ballots file FileIO ballotFile = new FileIO(nullFile.getBallotsFileName()); _ballots = ballotFile.createBallots(); buttons = new ArrayList<JToggleButton>(); for (Ballot ballot : _ballots) { JToggleButton[] ballotButtons = ballot.getButtons(); for (int i = 0; i < ballotButtons.length; i++) { buttons.add(ballotButtons[i]); } } }
// Update the true/false value of every button in the program, and set every value to its // respective position in the votes array public void updateButtons(String text) { FileIO nullFile = new FileIO(); // need to create this just to gain access to the filename of the ballots file FileIO ballotFile = new FileIO(nullFile.getBallotsFileName()); _ballots = ballotFile.createBallots(); buttons = new ArrayList<JToggleButton>(); for (Ballot ballot : _ballots) { JToggleButton[] ballotButtons = ballot.getButtons(); for (int i = 0; i < ballotButtons.length; i++) { buttons.add(ballotButtons[i]); } } int numButtons = 0; for (Ballot ballot : _ballots) { numButtons += ballot.getButtons().length; } for (int i = 0; i < numButtons; i++) { if (buttons.get(i).getText().equals(text)) { votes[i] = true; } } }