예제 #1
0
  // This method starts from the ButtonListener class but ends up in the Ballot class, updating the
  // file of each Ballot
  public void updateBallots() {
    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());
    ArrayList<Ballot> ballots = ballotFile.createBallots();

    for (Ballot ballot : ballots) {
      ballot.updateFile();
    }
  }
예제 #2
0
 // 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]);
     }
   }
 }
예제 #3
0
  // Grab the number of buttons from all of the ballots in the program.
  // This will define the votes array, which stores all of the true and false values...
  // as to whether the button is really selected or not (because button.isSelected() won't work for
  // me for some reason).
  public void setVotesLength() {
    FileIO nullFile =
        new FileIO(); // need to create this just to gain access to the filename of the ballots file
    FileIO ballotsFile = new FileIO(nullFile.getBallotsFileName());
    ArrayList<Ballot> throwAwayList = ballotsFile.createBallots();
    int numButtons = 0;

    for (Ballot ballot : throwAwayList) {
      numButtons += ballot.getNumButtons();
    }

    votes = new boolean[numButtons];
  }
예제 #4
0
  // 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;
      }
    }
  }