title: JavaFX Assigning action to all buttons in an array of arrays using for-loop
body: <p>We have this warm up exercise where we're supposed to create this reallllly simple game which's UI is pretty much set up</p>
  <p><img src="https://i.stack.imgur.com/HCW4C.png" alt="which's UI is pretty much set up" />.</p>
  <p>I got the error <strong>&quot;Local variable i defined in an enclosing scope must be final or effectively final&quot;.</strong></p>
  <p>I didn't understand it, so I googled it, but most of the problems are different.
  While typing this question I found this in the stackoverflow suggestions:</p>
  <p><a href="https://stackoverflow.com/questions/33323804/assigning-an-action-to-each-button-in-an-array-of-buttons-in-javafx">Assigning an action to each button, in an array of buttons in JavaFX</a></p>
  <p>But I simply don't understand. I'm learning programming/java from scratch. I hope JavaFX/GuI stuff isn't a hindrance?</p>
  <p>The code below only includes my attempt to assign the actions. I separated it from the creation of the buttons for the time being to figure out what the problem is. The problem is only in the if and else conditions.</p>
  <pre><code>    for(int i=0; i&lt;=4; i++) {
  
          for(int j=0; j&lt;=4; j++) {
  
              buttonGrid[i][j].setOnAction(new EventHandler&lt;ActionEvent&gt;() {
                  public void handle(ActionEvent event) {
                      
                      if (buttonGrid[i][j].getText() == &quot;X&quot;) {
                          buttonGrid[i][j].setText(&quot;O&quot;);
                      } else {
                          buttonGrid[i][j].setText(&quot;X&quot;);
                      }
                  }
              });
           }
      }
  </code></pre>
  <p>For now I just want the button's labels to change from X to O and from O to X as you click them. Btw. If I learn JavaFX and GUI, does it mean I HAVE to learn css? (Not that I don't want to, just.. not now)</p>
  <p>If there is a need for the rest of the code to figure the problem:
  <a href="http://textuploader.com/5b1kh" rel="nofollow noreferrer">http://textuploader.com/5b1kh</a></p>
  <p>I'd also appreciate if someone could tell me how to do the Scenes in a more efficent way. (Btw, can I somehow lock the aspect ratio of the sides of all cells of a gridpane?)</p>