title: How to increase a variable after every JButton click?
body: <p>I am working on a program that simulates a soccer match. I have a button, which randomly one of the two teams will give a point when I click on it. So, after one click, the score could be 1-0 or 0-1, and after two cliks 2-0, 0-2 or 1-1. </p>
  
  <p>The problem is that, every time I click, it is 0-1 or 1-0. So the score does not count on. </p>
  
  <p>I know that the reason is that I said <code>int homescore = 0</code> and <code>int awayscore = 0</code> in the 'action performed' code. And after this 0-0 it gives randomly one of the teams 1 point. So when I click for the second time on the button, the score will start at 0-0 again, not on the new score.</p>
  
  <p>Does someone know how I can solve this problem? Maybe it's very easy, but I haven't programmed often.</p>
  
  <p>This is the part of the code I'm talking about:</p>
  
  <pre><code>private void resultbuttonActionPerformed(java.awt.event.ActionEvent evt) {                                              
      Random dice = new Random();
      int number;
      int homescore = 0; 
      int awayscore = 0;
      for (int counter =1; counter&lt;=1; counter++){
          number = dice.nextInt(2);                   // Creates a 0 or a 1
          if (number == 1){                           // If 1: Point to home team
              homescore = ++homescore;}             
          else {                                      // If 0: Point to away team
              awayscore = ++awayscore;
                      }
          }
  
  
      homescorelabel.setText(String.valueOf(homescore));
      awayscorelabel.setText(String.valueOf(awayscore));
  </code></pre>