title: Why wont my game resume game play after button click?
body: <p>I'm trying to have the JButton 'back' return to the game, I have the running boolean printing when the game is running. It starts running after i click the button, but the rest of my thread is frozen, why is that and how can i fix this?</p>
  
  <p>I have tried adding a debug line that displays the running status(in the while loop and inside the if(running) statement, and outside the if statement) and after I click the back button, it shows running as true.  This should indicate that the rest of the thread should be working, but it is not. So when I hit the escape key, it sets running to false and displays the button. When I click back, running is set to true again and repaints the screen. the check place says it is running again but the screen still doesn't accept user input or update.</p>
  
  <pre><code>   private static final long serialVersionUID = 1L;
  
      static JPanel panel;
      Client client = Multiplayer.client;
  
      // map variables
      ArrayList&lt;Integer&gt; world = new ArrayList&lt;Integer&gt;();
      int width, height;
      int visibleWidth = 20;
      int visibleHeight = 20;
      int count = 0;
  
      static boolean running = true;
  
      // map variables
      int xOffset = 0, yOffset = 0;
      static double speed = 1;
  
      // game loop variables
      double interpolation = 0;
      final int TICKS_PER_SECOND = 25;
      final int SKIP_TICKS = 1000 / TICKS_PER_SECOND;
      final int MAX_FRAMESKIP = 5;
  
      // option menu
  
      JButton exit;    
      static JButton back;
  
      JButton options;    
      Player player = Multiplayer.client.player;
  
      public MainPanel(int width, int height) {
          this.width = width;
          this.height = height;
  
          this.panel = this;
          panel.setSize(new Dimension(width, height));
          panel.requestFocus();
  
          // add option menu buttons
          panel.setLayout(new GridBagLayout());
          GridBagConstraints gbc = new GridBagConstraints();
          exit = new Button("Exit", Loader.cropImage(Loader.loadImage("/SpriteSheet.png"), 7, 0, 96, 32),
                  Loader.cropImage(Loader.loadImage("/SpriteSheet.png"), 9, 0, 96, 32));
          back = new Button("Back", Loader.cropImage(Loader.loadImage("/SpriteSheet.png"), 7, 0, 96, 32),
                  Loader.cropImage(Loader.loadImage("/SpriteSheet.png"), 9, 0, 96, 32));
          options = new Button("Options", Loader.cropImage(Loader.loadImage("/SpriteSheet.png"), 7, 0, 96, 32),
                  Loader.cropImage(Loader.loadImage("/SpriteSheet.png"), 9, 0, 96, 32));
          gbc.insets = new Insets(1, 10, 1, 10);
          gbc.gridx = 0;
          gbc.gridy = 0;
          options.setVisible(false);
          exit.setVisible(false);
          back.setVisible(false);
          panel.add(options, gbc);
          gbc.gridy = 1;
          panel.add(back, gbc);
          gbc.gridy = 2;
          panel.add(exit, gbc);
  
          panel.setVisible(true);
  
          back.addActionListener(new ActionListener() {    
  
              public void actionPerformed(ActionEvent e) {
                  clearButtons();
                  return;
              }               
          });
  
          try {
              WorldGenerator(Multiplayer.client.f);
          } catch (IOException e) {
              e.printStackTrace();
          }    
      }
  
      public void clearButtons() {
          running = true;
          options.setVisible(false);
          exit.setVisible(false);
          back.setVisible(false);
          this.repaint();
      }
      public void WorldGenerator(File file) throws IOException {
  
          FileReader fr = new FileReader(file);
          BufferedReader br = new BufferedReader(fr);
          String line = "";
          while ((line = br.readLine()) != null) {
              // System.out.println(line);
              for (int i = 0; i &lt; line.length(); i++) {
                  world.add(Integer.parseInt(line.charAt(i) + ""));
              }
          }
          br.close();
          fr.close();
      }
  
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
  
          // render map
          for (int y = 0; y &lt; Multiplayer.client.worldHeight; y++) {
              for (int x = 0; x &lt; Multiplayer.client.worldWidth; x++) {
  
                  if (count == world.size()) {
                      count = 0;
                  }
  
                  g.drawImage(Tile.getTexture(world.get(count)), (x * Tile.WIDTH) + xOffset, (y * Tile.HEIGHT) + yOffset,
                          null);
                  count++;
  
              }
  
          }
  
          // render player and position
          for (int i = 0; i &lt; Multiplayer.client.entityList.size(); i++) {
              if (Multiplayer.client.entityList.get(i) instanceof Player) {
                  if (Multiplayer.client.entityList.get(i).getUUID() == player.getUUID()) {
                      g.drawImage(player.getImg(), player.getX(), player.getY(), null);
                      g.setColor(Color.RED);
                      // player bounds box
                      g.drawRect(player.getX(), player.getY(), player.width, player.height);
  
                      // System.out.println(xOffset + ", " + yOffset);
                  } else {
                      g.drawImage(Multiplayer.client.entityList.get(i).getImg(),
                              Multiplayer.client.entityList.get(i).getX(), Multiplayer.client.entityList.get(i).getY(),
                              null);
                  }
              }
          }
          //options menu backdrop
          if(!running) {
              g.setColor(new Color(0,0,0,85));
              g.fillRect(0, 0, panel.getWidth(), panel.getHeight());
          }
      }       
  
      @Override
      public void run() {
          long lastLoopTime = System.nanoTime();
          final int TARGET_FPS = 60;
          final long OPTIMAL_TIME = 1000000000 / TARGET_FPS;
          long lastFpsTime = 0;
  
          while (true) {
              long now = System.nanoTime();
              long updateLength = now - lastLoopTime;
              lastLoopTime = now;
              double delta = updateLength / ((double) OPTIMAL_TIME);
  
              lastFpsTime += updateLength;
              if (lastFpsTime &gt;= 10000000) {
                  lastFpsTime = 0;
                  System.out.println(running);
  
                  // escape - options menu
                  if (Keyboard.keys.contains(27) ) {
                      if(running) {
                          running = false;
                          back.setVisible(true);
                          this.repaint();                         
                      }
                      else {
                          running = true;
                          back.setVisible(false);
                          this.repaint();
                      }
                      try {
                          Thread.sleep(300);
                      } catch (InterruptedException e) {
                          e.printStackTrace();
                      }
                  }
  
                      // left - done
                      if (Keyboard.keys.contains(37)) {
                          if (player.getX() &lt; panel.getWidth() / 6 &amp;&amp; xOffset &lt; 0) {
                              xOffset += speed;
                              player.setX(panel.getWidth() / 6);
                          }
                          if (Tile.getTile(Tile.getTileAt(((player.getX() - 1) / Tile.WIDTH),
                                  (player.getY() / Tile.HEIGHT))).isSolid
                                  || Tile.getTile(Tile.getTileAt(((player.getX() - 1) / Tile.WIDTH),
                                          (player.getY() / Tile.WIDTH) + ((player.height / 2) / Tile.HEIGHT))).isSolid
                                  || Tile.getTile(Tile.getTileAt(((player.getX() - 1) / Tile.WIDTH),
                                          ((player.getY() / Tile.HEIGHT) + (player.height / Tile.HEIGHT)))).isSolid) {
                          } else {
                              player.setX((int) (player.getX() - speed));
                              client.sendMessage("0005;" + client.uuid + ";" + player.getX() + ";" + player.getY());
  
                          }
                      }
                      // right - done
                      if (Keyboard.keys.contains(39)) {
                          if (player.getX() + player.getWidth() &gt; (panel.getWidth() / 6) * 5
                                  &amp;&amp; (xOffset * -1) + panel.getWidth() &lt; client.worldWidth * Tile.WIDTH) {
                              xOffset -= speed;
                              player.setX(((panel.getWidth() / 6) * 5) - player.getWidth());
                          }
                          if (Tile.getTile(Tile.getTileAt(
                                  (((player.getX() + ((xOffset) * -1) + 1) / Tile.WIDTH) + (player.width / Tile.WIDTH)),
                                  (player.getY() / Tile.HEIGHT))).isSolid
                                  || Tile.getTile(Tile.getTileAt(
                                          (((player.getX() + ((xOffset) * -1) + 1) / Tile.WIDTH)
                                                  + (player.width / Tile.WIDTH)),
                                          (player.getY() / Tile.HEIGHT) + ((player.height / 2) / Tile.HEIGHT))).isSolid
                                  || Tile.getTile(Tile.getTileAt(
                                          (((player.getX() + ((xOffset) * -1) + 1) / Tile.WIDTH)
                                                  + (player.width / Tile.WIDTH)),
                                          (player.getY() / Tile.HEIGHT) + (player.height / Tile.HEIGHT))).isSolid) {
                          } else {
                              player.setX((int) (player.getX() + speed));
                              client.sendMessage("0005;" + client.uuid + ";" + player.getX() + ";" + player.getY());
  
                          }
                      }
  
                      // up
                      if (Keyboard.keys.contains(38)) {
                          if (player.getY() &lt; panel.getHeight() / 8 &amp;&amp; yOffset &lt; 0) {
                              yOffset += speed;
                              player.setY(panel.getHeight() / 8);
                          }
                          if (Tile.getTile(Tile.getTileAt((player.getX() / Tile.WIDTH),
                                  ((player.getY() + ((yOffset) * -1) - 2) / Tile.HEIGHT))).isSolid
                                  || Tile.getTile(
                                          Tile.getTileAt((player.getX() / Tile.WIDTH) + (player.width / Tile.WIDTH),
                                                  ((player.getY() + ((yOffset) * -1) - 2) / Tile.HEIGHT))).isSolid) {
                          } else {
                              player.setY((int) (player.getY() - speed));
                              client.sendMessage("0005;" + client.uuid + ";" + player.getX() + ";" + player.getY());
  
                          }
                      }
                      // down
                      if (Keyboard.keys.contains(40)) {
                          if (player.getY() + player.getHeight() &gt; (panel.getHeight() / 8) * 7
                                  &amp;&amp; (yOffset * -1) + panel.getHeight() &lt; client.worldHeight * Tile.HEIGHT) {
                              yOffset -= speed;
                              player.setY(((panel.getHeight() / 8) * 7) - player.getHeight());
                          }
                          if (Tile.getTile(Tile.getTileAt((player.getX() / Tile.WIDTH),
                                  ((player.getY() + ((yOffset) * -1) + 1) / Tile.HEIGHT)
                                          + (player.height / Tile.HEIGHT))).isSolid
                                  || Tile.getTile(
                                          Tile.getTileAt((player.getX() / Tile.WIDTH) + (player.width / Tile.WIDTH),
                                                  ((player.getY() + ((yOffset * -1)) + 1) / Tile.HEIGHT)
                                                          + (player.height / Tile.HEIGHT))).isSolid) {
                          } else {
                              player.setY((int) (player.getY() + speed));
                              client.sendMessage("0005;" + client.uuid + ";" + player.getX() + ";" + player.getY());
  
                          }
                      }
  
                      this.repaint();                 
              }
          }
      }
    }
  </code></pre>