Question: * * * JavaFX * * * * I can't get my button to 'roll' the dice images, and I had the images displayed but
JavaFXI can't get my button to 'roll' the dice images, and I had the images displayed but now it keeps giving me errors. Help???
import java.ioFileInputStream;
import java.ioFileNotFoundException;
import java.ioInputStream;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class RollingDice extends Application
@Override
public void startStage primaryStage throws FileNotFoundException
DicePane dice new DicePane;
VBox pane new VBox;
pane.setSpacing;
pane.setAlignmentPosCENTER;
Button btRoll new ButtonRoll;
pane.getChildrenaddbtRoll;
btRoll.setOnActionnew DiceRoll;
BorderPane borderPane new BorderPane;
borderPane.setCenterdice;
borderPane.setBottompane;
Scene scene new SceneborderPane;
primaryStage.setTitleRoll Dice";
primaryStage.setScenescene;
primaryStage.show;
class DiceRoll implements EventHandler
@Override
public void handle ActionEvent e
DicePane.roll;
public static void mainString args
launchargs;
class DicePane extends StackPane
private static ImageView imageView;
public DicePane throws FileNotFoundException
getChildrenaddimageView;
setAlignmentPosCENTER;
roll;
public static void roll throws FileNotFoundException
int randomDie intMathrandom;
switchrandomDie
case : InputStream oneGraphic new FileInputStreamsrcdiceonepng;
Image oneSide new ImageoneGraphic;
imageView new ImageViewoneSide;
break;
case : InputStream twoGraphic new FileInputStreamsrcdicetwopng;
Image twoSide new ImagetwoGraphic;
imageView new ImageViewtwoSide;
break;
case : InputStream threeGraphic new FileInputStreamsrcdicethreepng;
Image threeSide new ImagethreeGraphic;
imageView new ImageViewthreeSide;
break;
case : InputStream fourGraphic new FileInputStreamsrcdiceforpng;
Image fourSide new ImagefourGraphic;
imageView new ImageViewfourSide;
break;
case : InputStream fiveGraphic new FileInputStreamsrcdicefivepng;
Image fiveSide new ImagefiveGraphic;
imageView new ImageViewfiveSide;
break;
case : InputStream sixGraphic new FileInputStreamsrcdicesixpng;
Image sixSide new ImagesixGraphic;
imageView new ImageViewsixSide;
break;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
