title: passing data between JPanels
body: <p>I'm making Tetris in Java and would like to have the game play on the left and scoring, buttons, and nextPiece on the right, like so:</p>
  <p><img src="https://i.stack.imgur.com/afXrE.png" alt="enter image description here" /></p>
  <p>You'll notice that the score on the Game Panel is updating, but the score on the Score Panel (on the right) is not.</p>
  <p>On the Game Panel, I have global variables for score and level: <code>private int level, totalScore;</code> which are initialized to 0.</p>
  <p>and this in my <code>paint component():</code></p>
  <pre><code>        g.setColor(Color.RED);
          g.drawString(&quot;Level: &quot; + level, this.getWidth()/2+110, this.getHeight()/2-200);
          g.drawString(&quot;Score: &quot; + totalScore, this.getWidth()/2+110, this.getHeight()/2-170);
  </code></pre>
  <p>Then I have this code within the Game Panel which calculates level and scoring:</p>
  <pre><code>public void changeLevel () {
      int max = (level+1)*100;
      if (totalScore &gt;= max) {
          System.out.println(max + &quot;reached... next level&quot;);
          level++;
          totalScore = 0;
          timer();
      }
  }
  
  public int tallyScore(int totalLines) {
      int score = 0;
      switch (totalLines) {
          case 1: score = 40 * (level + 1);
                  break;
          case 2: score = 100 * (level + 1);
                  break;
          case 3: score = 300 * (level + 1);
                  break;
          case 4: score = 1200 * (level + 1); 
                  break;
          default: break;
      }
      return score;
  }
  
  //loop through all rows starting at bottom (12 rows)
  public void checkBottomFull() {
      int lines = 0;
      for(int row = totalRows-1; row &gt; 0; row--) {
          while (isFull(row)) {       
              lines++;
              clearRow(row);   
          }
      }
      totalScore += tallyScore(lines);    
      //check if level needs to be changed based on current score...
      changeLevel();
      //reset lines after score has been incremented
      lines=0;
  }
  </code></pre>
  <p>And since I want the Score Panel to display the score, I have these two methods in Game Panel which return the global variables:</p>
  <pre><code>public int getScore() {
      return totalScore;
  }
  public int getLevel() {
      return level;
  }
  </code></pre>
  <p>In my Score Panel <code>paintComponent()</code> I have <code>board.getLevel()</code> and <code>board.getScore()</code> (<code>board</code> class is the Game Panel) so I can feed the Game Panel scores to the Score Panel.</p>
  <pre><code>    g.setColor(Color.BLACK);
      g.drawString(&quot;Level: &quot; + board.getLevel(), this.getWidth()/2, this.getHeight()/2-130);
      g.drawString(&quot;Score: &quot; + board.getScore(), this.getWidth()/2, this.getHeight()/2-100);
  </code></pre>
  <p>Yet as you can see from the picture, these scores are not updating.</p>
  <p>Any thoughts?</p>
  <p>Thanks!</p>