title: Restarting the while loop
body: <p>I'm trying to restart the while loop. I've declared variable keepGoing of boolean type. If int variable x is off the window, keepGoing changes to false. Then the reset() method have to keepGoing=true. It works but the while loop isn't working.</p>
  
  <p>Class with reset() and checkWin():</p>
  
  <pre><code>private void reset() {
      b.x = 250;
      b.y = 100;
      b.keepRunning = true;
      a.keepGoing = true;
      System.out.println(a.keepGoing);
  }
  
  public void checkWin() {
      if (b.keepRunning) {
          if (b.getX() &lt; -10) {
              a.score++;
  
              JOptionPane.showMessageDialog(okno, "Player " + p.getScore()
                      + " - Computer " + a.getScore(), "Oh, well...",
                      JOptionPane.INFORMATION_MESSAGE);
              b.keepRunning = false;
              a.keepGoing = false;
              System.out.println(a.keepGoing);
              reset();
          } else if (b.getX() &gt; 599) {
              p.score++;
              JOptionPane.showMessageDialog(okno, "Player " + p.getScore()
                      + " - Computer " + a.getScore(), "Good!",
                      JOptionPane.INFORMATION_MESSAGE);
              b.keepRunning = false;
              a.keepGoing = false;
              System.out.println(a.keepGoing);
              reset();
          }
      }
  }
  </code></pre>
  
  <p>Second class with thread, keepGoing and the while loop:</p>
  
  <pre><code>Runnable intel = new Runnable() {
      public void run() {
          while (keepGoing) {
              while (getY() &lt; board.ball.getY()) {
                  System.out.println(keepGoing + " " + getY());
                  try {
                      if (y == 220) {
                      } else {
                          y += 1;
                          Thread.sleep(10);
                      }
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
              while (getY() &gt; board.ball.getY()) {
                  System.out.println(keepGoing + " " + getY());
                  try {
                      if (y == 0) {
                      } else {
                          y -= 1;
                          Thread.sleep(10);
                      }
                  } catch (InterruptedException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
              }
          }
      }
  };
  </code></pre>