title: Java GUI Repeatable Process
body: <p>I recently took up Java and I decided to construct a mini rock paper scissors game. Although, I think it turned out working but badly designed it still has a small problem. I cannot seem to figure out how to make the whole process repeatable because I have to restart the program so that the computer can choose once again between rock, paper or scissors. This is my code: </p>
  
  <pre><code>public class Panel extends JPanel implements ActionListener {
  
      int randomNum = new Random().nextInt(3) + 1;
  
      String AIGuess;
      String myGuess;
  
      boolean playAgain = true;
  
      JButton rock = new JButton("Rock");
      JButton paper = new JButton("Paper");
      JButton scissors = new JButton("Scissors");
  
      JLabel AIGuessDisplay = new JLabel(AIGuess);
  
      public Panel() {
          setLayout(new FlowLayout());
          add(rock);
          rock.addActionListener(
                    new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                              myGuess = "Rock";
                              if (randomNum == 1) {
                                  AIGuess = "Rock";
                                  JOptionPane.showMessageDialog(null, "Tie");
                              }
                              if (randomNum == 2) {
                                  AIGuess = "Paper";
                                  JOptionPane.showMessageDialog(null, "You Lose");
                              }
                              if (randomNum == 3) {
                                  AIGuess = "Scissors";
                                  JOptionPane.showMessageDialog(null, "You Win");
                              }
                          }
                        }
                      );
          add(paper);
          paper.addActionListener(
                    new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                              myGuess = "Paper";
                              if (randomNum == 1) {
                                  AIGuess = "Rock";
                                  JOptionPane.showMessageDialog(null, "You Win");
                              }
                              if (randomNum == 2) {
                                  AIGuess = "Paper";
                                  JOptionPane.showMessageDialog(null, "Tie");
                              }
                              if (randomNum == 3) {
                                  AIGuess = "Scissors";
                                  JOptionPane.showMessageDialog(null, "You Lose");
                              }
                          }
                        }
                      );
  
          add(scissors);
          scissors.addActionListener(
                    new ActionListener() {
                          public void actionPerformed(ActionEvent e) {
                              myGuess = "Scissors";
                              if (randomNum == 1) {
                                  AIGuess = "Rock";
                                  JOptionPane.showMessageDialog(null, "You Lose");
                              }
                              if (randomNum == 2) {
                                  AIGuess = "Paper";
                                  JOptionPane.showMessageDialog(null, "You Win");
                              }
                              if (randomNum == 3) {
                                  AIGuess = "Scissors";
                                  JOptionPane.showMessageDialog(null, "Tie");
                              }
                          }
                        }
                      );
          add(AIGuessDisplay);
      }
  
      @Override
      public void actionPerformed(ActionEvent e) {
          // TODO Auto-generated method stub
  
      }   
  }
  </code></pre>