I have this project and i have to implement a game. The game is Yahtzee and I need the picture to change after a dice is rolled. So when i call the function and I get a one, the dice image should change to another one I saved as diceFace1 (f.e.). Here is one of the images as it pre-loads
<ImageView fx:id="dice1" fitHeight="66.0" fitWidth="75.0" nodeOrientation="INHERIT" pickOnBounds="true" preserveRatio="true">
<HBox.margin>
<Insets left="10.0" right="30.0" top="20.0" />
</HBox.margin>
<image>
<Image url="@../Dices/beforeRollDice.png" fx:id="dice1img"/>
</image>
</ImageView>
And here is a blueprint of the function:
public void rollDice() {
Dice Dice = new Dice();
int diceVal = Dice.roll();
File imgPath = new File("@../Dices/Side1.jpeg");
System.out.println(diceVal);
switch (diceVal) {
case 1:
dice1.setImage(new Image(imgPath.toURI().toString()));
break;
case 2:
//dice1.setImage(new Image(imgPath.toURI().toString()));
break;
case 3:
//dice1.setImage(new Image(imgPath.toURI().toString()));
break;
case 4:
//dice1.setImage(new Image(imgPath.toURI().toString()));
break;
case 5:
//dice1.setImage(new Image(imgPath.toURI().toString()));
break;
case 6:
//dice1.setImage(new Image(imgPath.toURI().toString()));
break;
}
}
}
Problem is that when I call the function, the new image wont appear and the old one goes blank.