javafx Array of Images Randomly Displayed BINGO












0















I am trying to get my list of images to display on a 5x5 grid. I cannot figure out what the issue is.



This is the assignment instructions:
Assignment:



Create image BINGO. Using the exercise 14.1 page 586 as a foundation: Write a program that randomly displays images on a Bingo card. This should be a 5X5 grid with the letters B I N G O across the top.



//package
package javafxapplication2;
//import
import javafx.application.Application;
import javafx.geometry.HPos;
import javafx.geometry.Pos;
import javafx.geometry.VPos;
import javafx.scene.Scene;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
import javafx.scene.image.ImageView;
import javafx.scene.image.Image;

/**
*
* @author travis.dutton
*/
public class JavaFXApplication2 extends Application {
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {

GridPane pane = new GridPane();
pane.setAlignment(Pos.CENTER);
pane.setHgap(5);
pane.setVgap(5);

ImageView flags;
flags = new ImageView[25];

flags[0] = new ImageView("images/1.png");
flags[1] = new ImageView("images/2.jpg");
flags[2] = new ImageView("images/3.gif");
flags[3] = new ImageView("images/4.gif");
flags[4] = new ImageView("images/5.jpg");
flags[5] = new ImageView("images/6.png");
flags[6] = new ImageView("images/7.gif");
flags[7] = new ImageView("images/8.jpg");
flags[8] = new ImageView("images/9.png");
flags[9] = new ImageView("images/10.png");
flags[10] = new ImageView("images/11.jpg");
flags[11] = new ImageView("images/12.png");
flags[12] = new ImageView("images/13.png");
flags[13] = new ImageView("images/14.png");
flags[14] = new ImageView("images/15.png");
flags[15] = new ImageView("images/16.png");
flags[16] = new ImageView("images/17.gif");
flags[17] = new ImageView("images/18.gif");
flags[18] = new ImageView("images/19.png");
flags[19] = new ImageView("images/20.jpg");
flags[20] = new ImageView("images/21.png");
flags[21] = new ImageView("images/22.png");
flags[22] = new ImageView("images/23.png");
// flags[23] = new ImageView("images/24.gif");
// flags[24] = new ImageView("images/25.png");

// pane.add(flags[0], 0, 0);
// pane.add(imageView2, 1, 0);
// pane.add(imageView3, 0, 1);
// pane.add(imageView4, 1, 1);

// for(int i = 0; i < flags.length; i++){
//
// GridPane.setRowIndex(flags[i],1);
// GridPane.setColumnIndex(flags[i],i);
// pane.getChildren().add(flags[i]);
// }

for(int i = 0; i < 5; i++){
for (int j = 0; j < 5; j++) {
ImageView image = new ImageView();
image.setColumnIndex(1);
image.getChildren(String.valueOf(flags));
pane.add(image, i, j);

}
}




// Create a scene and place it in the stage
Scene scene = new Scene(pane);
primaryStage.setTitle("Exercise14_01"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
}



/**
* The main method is only needed for the IDE with limited
* JavaFX support. Not needed for running from the command line.
*/
public static void main(String args) {
launch(args);//launch javafx
}//end main
}//end of class









share|improve this question



























    0















    I am trying to get my list of images to display on a 5x5 grid. I cannot figure out what the issue is.



    This is the assignment instructions:
    Assignment:



    Create image BINGO. Using the exercise 14.1 page 586 as a foundation: Write a program that randomly displays images on a Bingo card. This should be a 5X5 grid with the letters B I N G O across the top.



    //package
    package javafxapplication2;
    //import
    import javafx.application.Application;
    import javafx.geometry.HPos;
    import javafx.geometry.Pos;
    import javafx.geometry.VPos;
    import javafx.scene.Scene;
    import javafx.scene.control.TextField;
    import javafx.scene.layout.GridPane;
    import javafx.stage.Stage;
    import javafx.scene.image.ImageView;
    import javafx.scene.image.Image;

    /**
    *
    * @author travis.dutton
    */
    public class JavaFXApplication2 extends Application {
    @Override // Override the start method in the Application class
    public void start(Stage primaryStage) {

    GridPane pane = new GridPane();
    pane.setAlignment(Pos.CENTER);
    pane.setHgap(5);
    pane.setVgap(5);

    ImageView flags;
    flags = new ImageView[25];

    flags[0] = new ImageView("images/1.png");
    flags[1] = new ImageView("images/2.jpg");
    flags[2] = new ImageView("images/3.gif");
    flags[3] = new ImageView("images/4.gif");
    flags[4] = new ImageView("images/5.jpg");
    flags[5] = new ImageView("images/6.png");
    flags[6] = new ImageView("images/7.gif");
    flags[7] = new ImageView("images/8.jpg");
    flags[8] = new ImageView("images/9.png");
    flags[9] = new ImageView("images/10.png");
    flags[10] = new ImageView("images/11.jpg");
    flags[11] = new ImageView("images/12.png");
    flags[12] = new ImageView("images/13.png");
    flags[13] = new ImageView("images/14.png");
    flags[14] = new ImageView("images/15.png");
    flags[15] = new ImageView("images/16.png");
    flags[16] = new ImageView("images/17.gif");
    flags[17] = new ImageView("images/18.gif");
    flags[18] = new ImageView("images/19.png");
    flags[19] = new ImageView("images/20.jpg");
    flags[20] = new ImageView("images/21.png");
    flags[21] = new ImageView("images/22.png");
    flags[22] = new ImageView("images/23.png");
    // flags[23] = new ImageView("images/24.gif");
    // flags[24] = new ImageView("images/25.png");

    // pane.add(flags[0], 0, 0);
    // pane.add(imageView2, 1, 0);
    // pane.add(imageView3, 0, 1);
    // pane.add(imageView4, 1, 1);

    // for(int i = 0; i < flags.length; i++){
    //
    // GridPane.setRowIndex(flags[i],1);
    // GridPane.setColumnIndex(flags[i],i);
    // pane.getChildren().add(flags[i]);
    // }

    for(int i = 0; i < 5; i++){
    for (int j = 0; j < 5; j++) {
    ImageView image = new ImageView();
    image.setColumnIndex(1);
    image.getChildren(String.valueOf(flags));
    pane.add(image, i, j);

    }
    }




    // Create a scene and place it in the stage
    Scene scene = new Scene(pane);
    primaryStage.setTitle("Exercise14_01"); // Set the stage title
    primaryStage.setScene(scene); // Place the scene in the stage
    primaryStage.show(); // Display the stage
    }



    /**
    * The main method is only needed for the IDE with limited
    * JavaFX support. Not needed for running from the command line.
    */
    public static void main(String args) {
    launch(args);//launch javafx
    }//end main
    }//end of class









    share|improve this question

























      0












      0








      0


      0






      I am trying to get my list of images to display on a 5x5 grid. I cannot figure out what the issue is.



      This is the assignment instructions:
      Assignment:



      Create image BINGO. Using the exercise 14.1 page 586 as a foundation: Write a program that randomly displays images on a Bingo card. This should be a 5X5 grid with the letters B I N G O across the top.



      //package
      package javafxapplication2;
      //import
      import javafx.application.Application;
      import javafx.geometry.HPos;
      import javafx.geometry.Pos;
      import javafx.geometry.VPos;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.GridPane;
      import javafx.stage.Stage;
      import javafx.scene.image.ImageView;
      import javafx.scene.image.Image;

      /**
      *
      * @author travis.dutton
      */
      public class JavaFXApplication2 extends Application {
      @Override // Override the start method in the Application class
      public void start(Stage primaryStage) {

      GridPane pane = new GridPane();
      pane.setAlignment(Pos.CENTER);
      pane.setHgap(5);
      pane.setVgap(5);

      ImageView flags;
      flags = new ImageView[25];

      flags[0] = new ImageView("images/1.png");
      flags[1] = new ImageView("images/2.jpg");
      flags[2] = new ImageView("images/3.gif");
      flags[3] = new ImageView("images/4.gif");
      flags[4] = new ImageView("images/5.jpg");
      flags[5] = new ImageView("images/6.png");
      flags[6] = new ImageView("images/7.gif");
      flags[7] = new ImageView("images/8.jpg");
      flags[8] = new ImageView("images/9.png");
      flags[9] = new ImageView("images/10.png");
      flags[10] = new ImageView("images/11.jpg");
      flags[11] = new ImageView("images/12.png");
      flags[12] = new ImageView("images/13.png");
      flags[13] = new ImageView("images/14.png");
      flags[14] = new ImageView("images/15.png");
      flags[15] = new ImageView("images/16.png");
      flags[16] = new ImageView("images/17.gif");
      flags[17] = new ImageView("images/18.gif");
      flags[18] = new ImageView("images/19.png");
      flags[19] = new ImageView("images/20.jpg");
      flags[20] = new ImageView("images/21.png");
      flags[21] = new ImageView("images/22.png");
      flags[22] = new ImageView("images/23.png");
      // flags[23] = new ImageView("images/24.gif");
      // flags[24] = new ImageView("images/25.png");

      // pane.add(flags[0], 0, 0);
      // pane.add(imageView2, 1, 0);
      // pane.add(imageView3, 0, 1);
      // pane.add(imageView4, 1, 1);

      // for(int i = 0; i < flags.length; i++){
      //
      // GridPane.setRowIndex(flags[i],1);
      // GridPane.setColumnIndex(flags[i],i);
      // pane.getChildren().add(flags[i]);
      // }

      for(int i = 0; i < 5; i++){
      for (int j = 0; j < 5; j++) {
      ImageView image = new ImageView();
      image.setColumnIndex(1);
      image.getChildren(String.valueOf(flags));
      pane.add(image, i, j);

      }
      }




      // Create a scene and place it in the stage
      Scene scene = new Scene(pane);
      primaryStage.setTitle("Exercise14_01"); // Set the stage title
      primaryStage.setScene(scene); // Place the scene in the stage
      primaryStage.show(); // Display the stage
      }



      /**
      * The main method is only needed for the IDE with limited
      * JavaFX support. Not needed for running from the command line.
      */
      public static void main(String args) {
      launch(args);//launch javafx
      }//end main
      }//end of class









      share|improve this question














      I am trying to get my list of images to display on a 5x5 grid. I cannot figure out what the issue is.



      This is the assignment instructions:
      Assignment:



      Create image BINGO. Using the exercise 14.1 page 586 as a foundation: Write a program that randomly displays images on a Bingo card. This should be a 5X5 grid with the letters B I N G O across the top.



      //package
      package javafxapplication2;
      //import
      import javafx.application.Application;
      import javafx.geometry.HPos;
      import javafx.geometry.Pos;
      import javafx.geometry.VPos;
      import javafx.scene.Scene;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.GridPane;
      import javafx.stage.Stage;
      import javafx.scene.image.ImageView;
      import javafx.scene.image.Image;

      /**
      *
      * @author travis.dutton
      */
      public class JavaFXApplication2 extends Application {
      @Override // Override the start method in the Application class
      public void start(Stage primaryStage) {

      GridPane pane = new GridPane();
      pane.setAlignment(Pos.CENTER);
      pane.setHgap(5);
      pane.setVgap(5);

      ImageView flags;
      flags = new ImageView[25];

      flags[0] = new ImageView("images/1.png");
      flags[1] = new ImageView("images/2.jpg");
      flags[2] = new ImageView("images/3.gif");
      flags[3] = new ImageView("images/4.gif");
      flags[4] = new ImageView("images/5.jpg");
      flags[5] = new ImageView("images/6.png");
      flags[6] = new ImageView("images/7.gif");
      flags[7] = new ImageView("images/8.jpg");
      flags[8] = new ImageView("images/9.png");
      flags[9] = new ImageView("images/10.png");
      flags[10] = new ImageView("images/11.jpg");
      flags[11] = new ImageView("images/12.png");
      flags[12] = new ImageView("images/13.png");
      flags[13] = new ImageView("images/14.png");
      flags[14] = new ImageView("images/15.png");
      flags[15] = new ImageView("images/16.png");
      flags[16] = new ImageView("images/17.gif");
      flags[17] = new ImageView("images/18.gif");
      flags[18] = new ImageView("images/19.png");
      flags[19] = new ImageView("images/20.jpg");
      flags[20] = new ImageView("images/21.png");
      flags[21] = new ImageView("images/22.png");
      flags[22] = new ImageView("images/23.png");
      // flags[23] = new ImageView("images/24.gif");
      // flags[24] = new ImageView("images/25.png");

      // pane.add(flags[0], 0, 0);
      // pane.add(imageView2, 1, 0);
      // pane.add(imageView3, 0, 1);
      // pane.add(imageView4, 1, 1);

      // for(int i = 0; i < flags.length; i++){
      //
      // GridPane.setRowIndex(flags[i],1);
      // GridPane.setColumnIndex(flags[i],i);
      // pane.getChildren().add(flags[i]);
      // }

      for(int i = 0; i < 5; i++){
      for (int j = 0; j < 5; j++) {
      ImageView image = new ImageView();
      image.setColumnIndex(1);
      image.getChildren(String.valueOf(flags));
      pane.add(image, i, j);

      }
      }




      // Create a scene and place it in the stage
      Scene scene = new Scene(pane);
      primaryStage.setTitle("Exercise14_01"); // Set the stage title
      primaryStage.setScene(scene); // Place the scene in the stage
      primaryStage.show(); // Display the stage
      }



      /**
      * The main method is only needed for the IDE with limited
      * JavaFX support. Not needed for running from the command line.
      */
      public static void main(String args) {
      launch(args);//launch javafx
      }//end main
      }//end of class






      java javafx






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 17 '18 at 5:12









      BigTravBigTrav

      62




      62
























          2 Answers
          2






          active

          oldest

          votes


















          0














          ImageView does not provide a getChildren method. (I don't know a JavaFX class that provides one that takes a String parameter btw). ImageViews are nodes and should be placed in the GridPane directly using the GridPane.add(Node, int, int) method.



          You can use Collections.shuffle to generate the premutation:



          String images = new String {
          "images/1.png",
          "images/2.jpg",
          ...
          "images/25.png"
          };

          // using a list with indices here to keep the original index order intact.
          // (You could use a list of String and shuffle it otherwise)
          List<Integer> permutation = IntStream.range(0, images.length).boxed().collect(Collectors.toCollection(ArrayList::new));
          Collections.shuffle(permutation);

          for(int i = 0, index = 0; i < 5; i++){
          for (int j = 1; j <= 5; j++) {
          ImageView image = new ImageView(images[permutation.get(index)]);
          pane.add(image, i, j);
          index++;
          }
          }

          // bingo accross the top (not sure if this is what was asked for)
          pane.add(new Label("Bingo"), 0, 0, 5, 1);





          share|improve this answer
























          • it worked! Thanks!

            – BigTrav
            Nov 19 '18 at 3:42











          • in this case, how would I resize all the images to: 250, 150, false, false?

            – BigTrav
            Nov 19 '18 at 3:50



















          0














          If you want put random images to GridPane, like:



          enter image description here



          you have to do something like this:



              final ArrayList<ImageView> flags = new ArrayList<>();

          flags.add(new ImageView("images/1.png"));
          flags.add(new ImageView("images/2.png"));
          flags.add(new ImageView("images/3.png"));
          // add flags

          for (int columnIndex = 0; columnIndex < 5; i++) {
          for (int rowIndex = 0; rowIndex < 5; j++) {
          if(isNotBingoCell(columnIndex, rowIndex)) { //check that cell is not BINGO cell
          final int imageIndex = Objects.equals(flags.size(), 1)
          ? 0
          : ThreadLocalRandom.current().nextInt(0, flags.size() - 1);
          pane.add(flags.get(imageIndex), columnIndex, rowIndex);
          flags.remove(imageIndex);
          flags.trimToSize();
          }
          }
          }


          , isNotBingoCell(...) implemintation:



              private boolean isNotBingoCell(int columnIndex, int rowIndex) {
          return !Objects.equals(columnIndex, rowIndex);
          }





          share|improve this answer

























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348443%2fjavafx-array-of-images-randomly-displayed-bingo%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            ImageView does not provide a getChildren method. (I don't know a JavaFX class that provides one that takes a String parameter btw). ImageViews are nodes and should be placed in the GridPane directly using the GridPane.add(Node, int, int) method.



            You can use Collections.shuffle to generate the premutation:



            String images = new String {
            "images/1.png",
            "images/2.jpg",
            ...
            "images/25.png"
            };

            // using a list with indices here to keep the original index order intact.
            // (You could use a list of String and shuffle it otherwise)
            List<Integer> permutation = IntStream.range(0, images.length).boxed().collect(Collectors.toCollection(ArrayList::new));
            Collections.shuffle(permutation);

            for(int i = 0, index = 0; i < 5; i++){
            for (int j = 1; j <= 5; j++) {
            ImageView image = new ImageView(images[permutation.get(index)]);
            pane.add(image, i, j);
            index++;
            }
            }

            // bingo accross the top (not sure if this is what was asked for)
            pane.add(new Label("Bingo"), 0, 0, 5, 1);





            share|improve this answer
























            • it worked! Thanks!

              – BigTrav
              Nov 19 '18 at 3:42











            • in this case, how would I resize all the images to: 250, 150, false, false?

              – BigTrav
              Nov 19 '18 at 3:50
















            0














            ImageView does not provide a getChildren method. (I don't know a JavaFX class that provides one that takes a String parameter btw). ImageViews are nodes and should be placed in the GridPane directly using the GridPane.add(Node, int, int) method.



            You can use Collections.shuffle to generate the premutation:



            String images = new String {
            "images/1.png",
            "images/2.jpg",
            ...
            "images/25.png"
            };

            // using a list with indices here to keep the original index order intact.
            // (You could use a list of String and shuffle it otherwise)
            List<Integer> permutation = IntStream.range(0, images.length).boxed().collect(Collectors.toCollection(ArrayList::new));
            Collections.shuffle(permutation);

            for(int i = 0, index = 0; i < 5; i++){
            for (int j = 1; j <= 5; j++) {
            ImageView image = new ImageView(images[permutation.get(index)]);
            pane.add(image, i, j);
            index++;
            }
            }

            // bingo accross the top (not sure if this is what was asked for)
            pane.add(new Label("Bingo"), 0, 0, 5, 1);





            share|improve this answer
























            • it worked! Thanks!

              – BigTrav
              Nov 19 '18 at 3:42











            • in this case, how would I resize all the images to: 250, 150, false, false?

              – BigTrav
              Nov 19 '18 at 3:50














            0












            0








            0







            ImageView does not provide a getChildren method. (I don't know a JavaFX class that provides one that takes a String parameter btw). ImageViews are nodes and should be placed in the GridPane directly using the GridPane.add(Node, int, int) method.



            You can use Collections.shuffle to generate the premutation:



            String images = new String {
            "images/1.png",
            "images/2.jpg",
            ...
            "images/25.png"
            };

            // using a list with indices here to keep the original index order intact.
            // (You could use a list of String and shuffle it otherwise)
            List<Integer> permutation = IntStream.range(0, images.length).boxed().collect(Collectors.toCollection(ArrayList::new));
            Collections.shuffle(permutation);

            for(int i = 0, index = 0; i < 5; i++){
            for (int j = 1; j <= 5; j++) {
            ImageView image = new ImageView(images[permutation.get(index)]);
            pane.add(image, i, j);
            index++;
            }
            }

            // bingo accross the top (not sure if this is what was asked for)
            pane.add(new Label("Bingo"), 0, 0, 5, 1);





            share|improve this answer













            ImageView does not provide a getChildren method. (I don't know a JavaFX class that provides one that takes a String parameter btw). ImageViews are nodes and should be placed in the GridPane directly using the GridPane.add(Node, int, int) method.



            You can use Collections.shuffle to generate the premutation:



            String images = new String {
            "images/1.png",
            "images/2.jpg",
            ...
            "images/25.png"
            };

            // using a list with indices here to keep the original index order intact.
            // (You could use a list of String and shuffle it otherwise)
            List<Integer> permutation = IntStream.range(0, images.length).boxed().collect(Collectors.toCollection(ArrayList::new));
            Collections.shuffle(permutation);

            for(int i = 0, index = 0; i < 5; i++){
            for (int j = 1; j <= 5; j++) {
            ImageView image = new ImageView(images[permutation.get(index)]);
            pane.add(image, i, j);
            index++;
            }
            }

            // bingo accross the top (not sure if this is what was asked for)
            pane.add(new Label("Bingo"), 0, 0, 5, 1);






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 17 '18 at 10:41









            fabianfabian

            51.1k115272




            51.1k115272













            • it worked! Thanks!

              – BigTrav
              Nov 19 '18 at 3:42











            • in this case, how would I resize all the images to: 250, 150, false, false?

              – BigTrav
              Nov 19 '18 at 3:50



















            • it worked! Thanks!

              – BigTrav
              Nov 19 '18 at 3:42











            • in this case, how would I resize all the images to: 250, 150, false, false?

              – BigTrav
              Nov 19 '18 at 3:50

















            it worked! Thanks!

            – BigTrav
            Nov 19 '18 at 3:42





            it worked! Thanks!

            – BigTrav
            Nov 19 '18 at 3:42













            in this case, how would I resize all the images to: 250, 150, false, false?

            – BigTrav
            Nov 19 '18 at 3:50





            in this case, how would I resize all the images to: 250, 150, false, false?

            – BigTrav
            Nov 19 '18 at 3:50













            0














            If you want put random images to GridPane, like:



            enter image description here



            you have to do something like this:



                final ArrayList<ImageView> flags = new ArrayList<>();

            flags.add(new ImageView("images/1.png"));
            flags.add(new ImageView("images/2.png"));
            flags.add(new ImageView("images/3.png"));
            // add flags

            for (int columnIndex = 0; columnIndex < 5; i++) {
            for (int rowIndex = 0; rowIndex < 5; j++) {
            if(isNotBingoCell(columnIndex, rowIndex)) { //check that cell is not BINGO cell
            final int imageIndex = Objects.equals(flags.size(), 1)
            ? 0
            : ThreadLocalRandom.current().nextInt(0, flags.size() - 1);
            pane.add(flags.get(imageIndex), columnIndex, rowIndex);
            flags.remove(imageIndex);
            flags.trimToSize();
            }
            }
            }


            , isNotBingoCell(...) implemintation:



                private boolean isNotBingoCell(int columnIndex, int rowIndex) {
            return !Objects.equals(columnIndex, rowIndex);
            }





            share|improve this answer






























              0














              If you want put random images to GridPane, like:



              enter image description here



              you have to do something like this:



                  final ArrayList<ImageView> flags = new ArrayList<>();

              flags.add(new ImageView("images/1.png"));
              flags.add(new ImageView("images/2.png"));
              flags.add(new ImageView("images/3.png"));
              // add flags

              for (int columnIndex = 0; columnIndex < 5; i++) {
              for (int rowIndex = 0; rowIndex < 5; j++) {
              if(isNotBingoCell(columnIndex, rowIndex)) { //check that cell is not BINGO cell
              final int imageIndex = Objects.equals(flags.size(), 1)
              ? 0
              : ThreadLocalRandom.current().nextInt(0, flags.size() - 1);
              pane.add(flags.get(imageIndex), columnIndex, rowIndex);
              flags.remove(imageIndex);
              flags.trimToSize();
              }
              }
              }


              , isNotBingoCell(...) implemintation:



                  private boolean isNotBingoCell(int columnIndex, int rowIndex) {
              return !Objects.equals(columnIndex, rowIndex);
              }





              share|improve this answer




























                0












                0








                0







                If you want put random images to GridPane, like:



                enter image description here



                you have to do something like this:



                    final ArrayList<ImageView> flags = new ArrayList<>();

                flags.add(new ImageView("images/1.png"));
                flags.add(new ImageView("images/2.png"));
                flags.add(new ImageView("images/3.png"));
                // add flags

                for (int columnIndex = 0; columnIndex < 5; i++) {
                for (int rowIndex = 0; rowIndex < 5; j++) {
                if(isNotBingoCell(columnIndex, rowIndex)) { //check that cell is not BINGO cell
                final int imageIndex = Objects.equals(flags.size(), 1)
                ? 0
                : ThreadLocalRandom.current().nextInt(0, flags.size() - 1);
                pane.add(flags.get(imageIndex), columnIndex, rowIndex);
                flags.remove(imageIndex);
                flags.trimToSize();
                }
                }
                }


                , isNotBingoCell(...) implemintation:



                    private boolean isNotBingoCell(int columnIndex, int rowIndex) {
                return !Objects.equals(columnIndex, rowIndex);
                }





                share|improve this answer















                If you want put random images to GridPane, like:



                enter image description here



                you have to do something like this:



                    final ArrayList<ImageView> flags = new ArrayList<>();

                flags.add(new ImageView("images/1.png"));
                flags.add(new ImageView("images/2.png"));
                flags.add(new ImageView("images/3.png"));
                // add flags

                for (int columnIndex = 0; columnIndex < 5; i++) {
                for (int rowIndex = 0; rowIndex < 5; j++) {
                if(isNotBingoCell(columnIndex, rowIndex)) { //check that cell is not BINGO cell
                final int imageIndex = Objects.equals(flags.size(), 1)
                ? 0
                : ThreadLocalRandom.current().nextInt(0, flags.size() - 1);
                pane.add(flags.get(imageIndex), columnIndex, rowIndex);
                flags.remove(imageIndex);
                flags.trimToSize();
                }
                }
                }


                , isNotBingoCell(...) implemintation:



                    private boolean isNotBingoCell(int columnIndex, int rowIndex) {
                return !Objects.equals(columnIndex, rowIndex);
                }






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 17 '18 at 8:33

























                answered Nov 17 '18 at 6:32









                kozmokozmo

                3861314




                3861314






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348443%2fjavafx-array-of-images-randomly-displayed-bingo%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    How to pass form data using jquery Ajax to insert data in database?

                    National Museum of Racing and Hall of Fame

                    Guess what letter conforming each word