Example #1
0
 public void mouseEntered(MouseEvent e) {
   JToggleButton btn = (JToggleButton) c;
   btn.setForeground(Color.red);
   btn.setBackground(Color.orange);
   Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
   btn.setCursor(cursor);
 }
Example #2
0
  public void addButton(JToggleButton b) {
    imagePanel.add(b);

    b.setForeground(Color.black);
    b.setBackground(Color.white);
    b.setFocusable(false);
    b.addMouseListener(new PopupMouseListener(b));
    b.addActionListener(new PopupActionListener(b));
  }
Example #3
0
 public void actionPerformed(ActionEvent e) {
   // String currentMessage = clientWindowFrame.massageField.getText();
   // clientWindowFrame.massageField.setText(currentMessage+"/*" +((JButton) c).getText()+"*/");
   JToggleButton btn = (JToggleButton) c;
   btn.setForeground(Color.black);
   btn.setBackground(Color.white);
   mouseMenu.setVisible(false);
   actionButton.setIcon(btn.getIcon());
   actionButton.setToolTipText(btn.getToolTipText());
 }
Example #4
0
 public void mouseExited(MouseEvent e) {
   JToggleButton btn = (JToggleButton) c;
   btn.setForeground(Color.black);
   btn.setBackground(Color.white);
 }
Example #5
0
  // This is where all the action happens.  If an action is performed (button press for example), it
  // goes through this method
  // that takes an ActionEvent, which is created at the time of the action.
  public void actionPerformed(ActionEvent e) {
    // Try to cast the ActionEvent source as JToggleButton (if successful, the button is a ballot
    // choice)
    try {
      JToggleButton theButton = (JToggleButton) e.getSource();
      String buttonText = theButton.getText();

      if (theButton.isSelected()) {
        theButton.setForeground(Color.RED);
        switchButton = true;
        switchButtonText = buttonText;
        updateButtons(
            buttonText); // switches this button's respective vote position to 1 (true), meaning it
                         // is selected
      } else if (!theButton.isSelected()) {
        theButton.setForeground(Color.BLACK);
        unvoteButton = true;
        unvoteButtonText = buttonText;
      }
      // If the program can't cast the source to a JToggleButton, cast it as a JButton, which is
      // 100% what the source will be at this point.
      // This button will be one of two things: the login button or the cast vote button.
    } catch (Exception exception) {
      JButton theButton = (JButton) e.getSource();

      String buttonText = theButton.getText();

      // If the user hits the Login button, check if the ID is valid.
      // If the ID is not valid, don't let them vote.  However, if it is valid, disable login and
      // enable everything else.
      if (buttonText.equals("Login")) {
        String voterID =
            JOptionPane.showInputDialog(theButton, "Enter your voter ID: ", "Login", 3);
        FileIO votersFile = new FileIO("voters.txt");
        ArrayList<Voter> voters = votersFile.createVoters();

        if (votersFile.checkValidID(voterID)) {
          Voter theVoter = voters.get(votersFile.getVoterIndex(voterID));
          if (theVoter.getVotedStatus().equals("false")) {
            setVoterID(voterID);
          } else {
            JOptionPane.showMessageDialog(
                theButton, "You already voted " + theVoter.getVoterName() + "!");
          }
        } else {
          JOptionPane.showMessageDialog(theButton, "Invalid ID!", "Error", 0);
        }
        // If the user hits the cast vote button, update the respective ballot files and disable
        // every button except
        // for the login button.
      } else if (buttonText.equals("Cast vote")) {
        int confirm = JOptionPane.showConfirmDialog(theButton, "Are you sure?");
        FileIO votersFile = new FileIO("voters.txt");
        ArrayList<Voter> voters = votersFile.createVoters();
        Voter theVoter = voters.get(votersFile.getVoterIndex(voterID));

        if (confirm == 0) {
          JOptionPane.showMessageDialog(theButton, "Thanks for voting!");
          updateBallots();
          votersFile.updateVoterFile(theVoter.getVoterID());
          setVoterID("-1");
          votersFile.initializeVoters();
        }
      }
    }
  }