Reputation: 48
My program creates a Black Jack game using a JavaFX GUI, however when I am inputting photos into the deck (ArrayList) it is not populating the ArrayList with the image paths. The paths are all very similar, they are c1.png or c2.png etc.
for (int i = 0; i < 13; i++) {
deck.add(new Image("file:images/c" + (i+1) + ".png"));
}
It should display images into JavaFX GUI when hard coded it works, but won't work in for loop
Upvotes: 0
Views: 60
Reputation: 1838
Try:
for (int i = 0; i < 13; i++) {
deck.add(new Image(new FileInputStream("C:\\images\\" + (i+1) + ".png"));
}
Also, make sure to cast your ArrayList
as ArrayList<Image>
:
List<Image> deck = new ArrayList<Image>();
Let me know if this helps you out.
Upvotes: 1