title: How to display a 10-by-10square matrix with JavaFX?
body: <p>JavaFX Basics write a program that displays a 10-by-10 square matrix. Each element in the matrix is 0 or 1, randomly generated. Display each number centered in a text field. Use TextField setText method to set value 0 or 1 as a string.
  As of now I can only print one random number. How can I make display a 10-by-10 matrix?</p>
  
  <pre><code>    import javafx.application.Application;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.layout.GridPane;
      import javafx.stage.Stage;
  
      import java.util.Random; 
  
      public class Matrix extends Application {
              public class Matrix extends Application {
  
      Button[][] matrix; //names the grid of buttons
  
      @Override
      public void start(Stage primaryStage) {
  
  int SIZE = 10;
  int length = SIZE;
  int width = SIZE;
  
  GridPane root = new GridPane();
  
  
  matrix = new Button[width][length]; 
  for(int y = 0; y &lt; length; y++)
  {
          for(int x = 0; x &lt; width; x++)
          {
              Random rand = new Random(); 
              int rand1 = rand.nextInt(2); 
  
              matrix[x][y] = new Button(/*"(" + rand1 + ")"*/); 
              matrix[x][y].setText("(" + rand1 + ")");   //
  
              matrix[x][y].setOnAction(new EventHandler&lt;ActionEvent&gt;() {
  
                  @Override
                  public void handle(ActionEvent event) {
                      System.out.println("Random Binary Matrix (JavaFX)");
                  }
              });
  
              root.getChildren().add(matrix[x][y]);
          }
  }        
  
  
  Scene scene = new Scene(root, 500, 500);
  
  primaryStage.setTitle("Random Binary Matrix (JavaFX)");
  primaryStage.setScene(scene);
  primaryStage.show();
      }
  
      public static void main(String[] args) {
  
          launch(args); 
              }
  
      }        
  </code></pre>