Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Programming: Visual Applications Code - - Consider the following \"voting\"

ID: 3607599 • Letter: J

Question

Java Programming: Visual Applications Code -

- Consider the following "voting" application, which has the following components:

(1) A button called yesButton which the user presses to increment yes votes.

(2) A button called noButton which the user presses to increment no votes.

(3) A textfield called winnerField which displays either yes or no, depending on which is currently winning.

(4) A Vote support object called vote that keeps track of the current votes.

public class VoteApp extends JFrame implements ActionListener {

private JButton yesButton = new JButton ("yes");

private JButton noButton = new JButton ("no");

private JTextField winnerField = new JTextField(5);

private Vote vote = new Vote(0, 0);

- Add code to the below actionPerformed mehtod that does the following:

(#1) - Determines which of the two buttons was pressed.

(#2) - Calls either the yesVote or noVote method of the vote object depending on the button pressed.

(#3) - Uses the getWinner method to find which is currently winning, and displays it in winnerField.

***************************************************************************************************************************************

Java Code -

public void actionPerformed (ActionEvent e) {

  ...........ADD CODE HERE..................

}

yes no yes

Explanation / Answer

Answer:

public void actionPerformed (ActionEvent e) {

if(e.getSource() == yesButton) {

vote.yesVote();

} else {

vote.noVote();

}

winnerField.setText(""+vote.getWinner())

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote