Hi i need help with a rock, paper, scissors game made in java purely gui. Must b
ID: 3634926 • Letter: H
Question
Hi i need help with a rock, paper, scissors game made in java purely gui.Must be created using JCreator or uploaded to be ready for use when opened.
Needs at least 4 separate classes: a Die class that will have 2 Constructors to
determine the range of the random numbers we need for the program, an RPS class that will
contain the main() method, a RPSframe class that will create the window (frame) that the game
will play in, and a RPSpanel class that has the guts of the program.
• setvisible (true) { set to false by default }
• Main will have few lines
• Have a button for options/direction, 1 for rock, 1 for paper, 1 for scissors, and something pretty.
• Pretty – {Pictures above rock , paper, and scissors}
• Use programming comments and appropriate use of “white space”
• Must run in GUI setting( absolutely no println )
• Keep track of wins/loses/draws and display at end of play session
• Let user play until they press close or cancel {play to completion}
• Directions – include in the directions screen{ Welcome to the rock, paper, scissors game.
If you need directions for this game then you’ve been living under a rock..
However.. Rock beats Scissors, Scissors beats paper, and paper beat rock, Enjoy}
Explanation / Answer
Java Code: import java.awt.event.*; import javax.swing.*; import java.awt.*; import static java.lang.Math.*; public class Final extends JFrame { private JLabel javaL,haha; private JButton colorB; private Container pane; private what stopHandler; private hi beginHandler; private umm middleHandler; private ButtonGroup ColorSelectBGroup; private JRadioButton one,two,three; private static final int WIDTH = 1000; private static final int HEIGHT = 500; public Final() { stopHandler = new what(); haha = new JLabel(" Please pick either: Rock, Paper, or Scissors."); one = new JRadioButton("Rock"); two = new JRadioButton("Paper"); three = new JRadioButton("Scissors"); colorB = new JButton("Random button here just for decoration.~ :D"); JLabel javaL = new JLabel("RANDOM LABEL THAT YOU ARE READING NOW.", SwingConstants.CENTER); setTitle("Welcome to: Java Programming - Rock, Paper, Scissors (Tr0ll style)"); pane = getContentPane(); pane.setLayout(new GridLayout(2,1)); pane.add(haha); pane.add(javaL); pane.add(colorB); ColorSelectBGroup = new ButtonGroup(); ColorSelectBGroup.add(one); ColorSelectBGroup.add(two); ColorSelectBGroup.add(three); pane.add(one); pane.add(two); pane.add(three); one.addActionListener(stopHandler); two.addActionListener(beginHandler); three.addActionListener(middleHandler); setSize(WIDTH, HEIGHT); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } private class what implements ActionListener { public void actionPerformed(ActionEvent e) { int rock = 1; int paper = 2; int scissors = 3; int random; random = (int)(Math.random() * 3) + 1; if (random == 2) { JOptionPane.showMessageDialog(null, "You've lost. Better luck next time. N00B."); JOptionPane.showMessageDialog(null, "Also, guess wut? You've lost the game. TROLOLOLO!"); } if (random == 1) { JOptionPane.showMessageDialog(null, "It's a tie. It's your lucky day."); } if (random == 3) { JOptionPane.showMessageDialog(null, "You've won. This time. But I promise that I will win eventually."); } } } private class hi implements ActionListener { public void actionPerformed(ActionEvent e) { int rock = 1; int paper = 2; int scissors = 3; int random; random = (int)(Math.random() * 3) + 1; if (random == 3) { JOptionPane.showMessageDialog(null, "You've lost. Better luck next time. N00B."); JOptionPane.showMessageDialog(null, "Also, guess wut? You've lost the game."); } if (random == 2) { JOptionPane.showMessageDialog(null, "It's a tie. It's your lucky day."); } if (random == 1) { JOptionPane.showMessageDialog(null, "You've won. This time. But I promise that I will win eventually."); } } } private class umm implements ActionListener { public void actionPerformed(ActionEvent e) { int rock = 1; int paper = 2; int scissors = 3; int random; random = (int)(Math.random() * 3) + 1; if (random == 1) { JOptionPane.showMessageDialog(null, "You've lost. Better luck next time. N00B."); JOptionPane.showMessageDialog(null, "Also, guess wut? You've lost the game."); } if (random == 3) { JOptionPane.showMessageDialog(null, "It's a tie. It's your lucky day."); } if (random == 2) { JOptionPane.showMessageDialog(null, "You've won. This time. But I promise that I will win eventually."); } } } public static void main(String[] args) { Final demoObject = new Final(); } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.