package eecs2030.lab5; import java.awt.Dimension; import java.awt.event.ActionListener; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.border.EmptyBorder; import javax.swing.border.EtchedBorder; public class RPSView extends JFrame { // DO NOT MAKE THESE FIELDS PRIVATE; THE TESTER NEEDS DIRECT // DIRECT ACCESS TO THEM JLabel player; // a label describing the hand played by the player JLabel computer; // a label describing the hand played by the computer JLabel winner; // a label describing who won the last round played JLabel record; // a label describing the won-lost-draw record of the rounds played JButton rock; // a button that allows the player to play the hand rock JButton paper; // a button that allows the player to play the hand paper JButton scissors; // a button that allows the player to play the hand scissors /** * Initializes a view for the game rock, paper, scissors. The constructor * has been implemented for you. * * @param listener * a listener for the button events */ public RPSView(ActionListener listener) { // 1. make the window by invoking the superclass constructor super("Rock, paper, scissors"); // 2. What happens when the frame closes? this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 3. make and add the controls this.makeLabels(); this.makeButtons(listener); // 4. Size the frame this.setMinimumSize(new Dimension(400, 400)); this.pack(); this.setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS)); // 5. Show the view; we'll do this in RPSGame // this.setVisible(true); } /** * Creates the four labels for the view. * *

* this.player
* This label is for the hand played by the player. * It should be initialized with the text "You picked: ". * *

* this.computer
* This label is for the hand played by the computer. It should be initialized * with the text "Computer picked: ". * *

* this.winner
* This label describes who won the last hand. It should be initialized * with the text "No winner yet". * *

* this.record
* This label describes the won-lost-draw record of the previously played hands. * It should be initialized with the text * "Games won: 0, Games lost: 0, Games drawn: 0". * *

* Each label should invoke the method setMaximumSize to set a * maximum size of 400 x 50 (width x height). * *

* Each label should invoke the method setBorder to set a nice * border. See the lab for details. * */ private void makeLabels() { } /** * Creates the three buttons for the view. * *

* this.rock
* The first button allows the player to choose the hand rock. * It should have the text equal to RPSUtils.ROCK. * It should set the action command string to RPSUtils.ROCK. * It should add the action listener listener. * *

* this.paper
* The second button allows the player to choose the hand paper. * It should have the text equal to RPSUtils.PAPER. * It should set the action command string to RPSUtils.PAPER. * It should add the action listener listener. * *

* this.scissors
* The third button allows the player to choose the hand scissors. * It should have the text equal to RPSUtils.SCISSORS. * It should set the action command string to RPSUtils.SCISSORS. * It should add the action listener listener. * *

* Each button should invoke the method setMaximumSize to set a * maximum size of 400 x 50 (width x height). * * @param listener */ private void makeButtons(ActionListener listener) { } /** * Sets the text of the player label. The text is the string: * *

* "You picked: " * *

* followed by the hand played by the player. * * @param player * the hand played by the player; assumed to be equal to one of * RPSUtils.ROCK, RPSUtils.PAPER, or RPSUtils.SCISSORS */ public void setPlayerLabel(String player) { } /** * Sets the text of the computer label. The text is the string: * *

* "Computer picked: " * *

* followed by the hand played by the computer. * * @param computer * the hand played by the computer; assumed to be equal to one of * RPSUtils.ROCK, RPSUtils.PAPER, or RPSUtils.SCISSORS */ public void setComputerLabel(String computer) { } /** * Sets the text of the label describing who won the hand. The text is the * string: * *

* "Computer wins" * *

* if the computer won the hand. * *

* The text is the string: * *

* "You win" * *

* if the player won the hand. * *

* The text is the string: * *

* "It's a draw" * *

* if the computer and player played the same hand. * * @param winner * the winner of the hand; assumed to be one of * RPSUtils.COMPUTER, RPSUtils.PLAYER, or RPSUtils.DRAW */ public void setWinner(String winner) { } /** * Sets the text of the label describing the record of hands won, lost, * and drawn by the player. Examples of the text are shown below: * *

     * "Games won: 1, Games lost: 0, Games drawn: 0"
     * "Games won: 0, Games lost: 1, Games drawn: 0"
     * "Games won: 0, Games lost: 0, Games drawn: 1"
     * "Games won: 12, Games lost: 11, Games drawn: 2"
     * 
* * @param gamesWon the number of games won by the player * @param gamesLost the number of games lost by the player * @param gamesDrawn the number of games that resulted in a draw */ public void setRecord(int gamesWon, int gamesLost, int gamesDrawn) { } /** * Used to test the appearance of the view without creating a model, controller, or game. * You can run this main method to see the appearance of the view (but pressing the * buttons won't trigger any events). * * @param args not used */ public static void main(String[] args) { (new RPSView(null)).setVisible(true); } }