title: JavaFx:What is a good practice to handle lots of buttons
body: <p>I am writing a project using JavaFx and it's a 3D-Tic Tac Toe, i have a 3D 4*4*4 page which i designed with scene builder 2.0 and placed a lot of buttons as controls, so when you click on a button its text turns to "R" and when computer selects its move, it's going to be "B",anyway here is a sample of my Controller class:</p>
  
  <pre><code>public class Controller {
  @FXML
  private Button b131;
  
  @FXML
  private Button b111;
  
  @FXML
  private Button b133;
  
  @FXML
  private Button b232;
  
  @FXML
  private Button b331;
  
  @FXML
  private Button b132;
  
  @FXML
  private Button b231;
  
  @FXML
  private Button b314;
  
  @FXML
  private Button b113;
  
  @FXML
  private Button b234;
  
  @FXML
  private Button b212;
  
  @FXML
  private Button b333;
  
  @FXML
  private Button b311;
  ...
   @FXML
  public void Initialize() {
      assert b131 != null : "fx:id=\"b131\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b111 != null : "fx:id=\"b111\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b133 != null : "fx:id=\"b133\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b232 != null : "fx:id=\"b232\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b331 != null : "fx:id=\"b331\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b132 != null : "fx:id=\"b132\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b231 != null : "fx:id=\"b231\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b314 != null : "fx:id=\"b314\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b113 != null : "fx:id=\"b113\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b234 != null : "fx:id=\"b234\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b212 != null : "fx:id=\"b212\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b333 != null : "fx:id=\"b333\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b311 != null : "fx:id=\"b311\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b112 != null : "fx:id=\"b112\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b134 != null : "fx:id=\"b134\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b233 != null : "fx:id=\"b233\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b211 != null : "fx:id=\"b211\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b332 != null : "fx:id=\"b332\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b214 != null : "fx:id=\"b214\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b313 != null : "fx:id=\"b313\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b114 != null : "fx:id=\"b114\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b213 != null : "fx:id=\"b213\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b334 != null : "fx:id=\"b334\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b312 != null : "fx:id=\"b312\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b142 != null : "fx:id=\"b142\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b241 != null : "fx:id=\"b241\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b141 != null : "fx:id=\"b141\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b122 != null : "fx:id=\"b122\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b144 != null : "fx:id=\"b144\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b243 != null : "fx:id=\"b243\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b221 != null : "fx:id=\"b221\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b342 != null : "fx:id=\"b342\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b121 != null : "fx:id=\"b121\" was not injected: check your FXML file 'Scene.fxml'.";
      assert b143 != null : "fx:id=\"b143\" was not injected: check your FXML file 'Scene.fxml'.";
  ...
  </code></pre>
  
  <p>I've set my buttons fx:id's in this logic,'b' stands for button, first integer refers to it's page and second and third integers stand for row and column of that button, Now my problem is event handling, i've written a function which does this and connected it to my button through scene builder's code section and it works :</p>
  
  <pre><code>public void ButtonHandler(){
  b111.setOnAction(new EventHandler&lt;javafx.event.ActionEvent&gt;() {
      @Override
      public void handle(javafx.event.ActionEvent event) {
          b111.setText("R");
      }
  });
  ...
  </code></pre>
  
  <p>But i want the button name to be kinda dynamic but i don't know how to do it efficiently.
  Any help would be appreciated.</p>