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 yesExplanation / Answer
Answer:
public void actionPerformed (ActionEvent e) {
if(e.getSource() == yesButton) {
vote.yesVote();
} else {
vote.noVote();
}
winnerField.setText(""+vote.getWinner())
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.