I am trying to add my images (which are cards) to some sort of list and shuffle them so they can be distributed out to the buttons.
The program is a matching game, so when you click on the "button/image", this will flip over and then you can try to match it with another covered card.
I'm unsure of how to add the images in a List and shuffle them. I am nowhere near an advanced level in java, so if you could keep it simple I would greatly appreciate it.
This is what I have come up with so far. I'm sure the list I have is completely wrong and I'm not sure how to shuffle it.
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.scene.layout.GridPane;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.File;
import java.io.IOException;
import java.awt.Color;
import java.awt.Graphics2D;
import javafx.scene.image.ImageView;
import java.util.Random;
import java.util.ArrayList;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import java.util.*;
public class FinalProject extends Application
{
private Button button;
private Button button1;
private Button button2;
private Button button3;
private Button button4;
/*private Button button5;
private Button button6;
private Button button7;
private Button button8;
private Button button9;
private Button button10;
private Button button11;
private Button button12;
private Button button13;
private Button button14;
private Button button15;
private Button button16;
private Button button17;*/
private Button startButton;
private Label label;
private int value;
private ImageView Clubs2IView;
private ImageView Diamonds2IView;
private ImageView Clubs3IView;
private ImageView Diamonds3IView;
private ArrayList<File> Cards;
private Image backCard;
private ImageView backCardIView;
public static void main(String[] args)
{
launch(args);
}
@Override
public void start(Stage primaryStage)
{
int counter = 0;
GridPane gridpane = new GridPane();
gridpane.add(button, 0, 0);
gridpane.add(button1, 1, 0);
gridpane.add(button2, 0, 1);
gridpane.add(button3, 1, 1);
/*gridpane.add(button4, 4, 0);
gridpane.add(button5, 6, 0);
gridpane.add(button6, 0, 1);
gridpane.add(button7, 0, 2);
gridpane.add(button8, 0, 3);
gridpane.add(button9, 0, 4);
gridpane.add(button10, 0, 5);
gridpane.add(button11, 1, 1);
gridpane.add(button12, 1, 2);
gridpane.add(button13, 1, 3);
gridpane.add(button14, 1, 4);
gridpane.add(button15, 1, 5);
gridpane.add(button16, 0, 0);*/
backCard = new Image("file:backCard.jpg");
backCardIView = new ImageView(backCard);
button.setGraphic(backCardIView);
Cards = new ArrayList<>();
Cards.add("file:2_Clubs.jpg");
Cards.add("2_Diamonds.jpg");
Cards.add("3_Clubs.jpg");
Cards.add("3_Diamonds.jpg");
/*Cards.add("file:2_Clubs.jpg");
Cards.add("file:2_Diamonds.jpg");
Cards.add("file:3_Clubs.jpg");
Cards.add("file:3_Diamonds.jpg");
cards.add("file:4_Clubs.jpg");
cards.add("file:4_Diamonds.jpg");
cards.add("file:5_Clubs.jpg");
cards.add("file:5_Diamonds.jpg");
cards.add("file:6_Clubs.jpg");
cards.add("file:6_Diamonds.jpg");
cards.add("file:7_Clubs.jpg");
cards.add("file:7_Diamonds.jpg");
cards.add("file:8_Clubs.jpg");
cards.add("file:8_Diamonds.jpg");
cards.add("file:9_Clubs.jpg");
cards.add("file:9_Diamonds.jpg");
cards.add("file:10_Clubs.jpg");
cards.add("file:10_Diamonds.jpg");*/
button.setOnAction(new EventHandler<ActionEvent>()
{
@Override
public void handle(ActionEvent event)
{
}
});
Scene scene = new Scene(gridpane);
primaryStage.setScene(scene);
primaryStage.setTitle("Matching");
primaryStage.show();
}
}