Using JavaFX create a Roll application that implements the GUI shown When the user clicks the Roll button, the program must roll the dice, change the figures randomly, calculate the sum of the dice and show it in a label
The program is written in Java 8 using Eclipse IDE and SceneBuilder for UI design
Main Program
package rollDice;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.stage.Stage;
import javafx.scene.Parent;
import javafx.scene.Scene;
public class RollDiceMain extends Application {
@Override
public void start(Stage primaryStage) {
try {
// loading the
FXML File
Parent root =
FXMLLoader.load(getClass().getResource("RollDiceFXML.fxml"));
Scene scene =
new Scene(root);
primaryStage.setTitle("Roll Dice");// setting title
primaryStage.setScene(scene);
primaryStage.setResizable(false);// seting resizable false
primaryStage.show();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
launch(args);
}
}
Controller Program
package rollDice;
import java.io.File;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class RollDiceController {
@FXML
private ImageView imageView1;
@FXML
private ImageView imageView2;
@FXML
private Label sum;
@FXML
void rollDiceOperation(ActionEvent event) {
int rollDice1, rollDice2;
//generating random number
rollDice1 = (int)(Math.random()*(7-1)+1);
rollDice2 = (int)(Math.random()*(7-1)+1);
//change the address of file accordingly
File file1 = new
File("C://Users//Acer//Desktop//die"+rollDice1+".png");
File file2 = new
File("C://Users//Acer//Desktop//die"+rollDice2+".png");
imageView1.setImage(new
Image(file1.toURI().toString()));
imageView2.setImage(new
Image(file2.toURI().toString()));
sum.setText("Points: "+(rollDice1+rollDice2));
}
}
FXML Program
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="372.0"
prefWidth="522.0" xmlns="http://javafx.com/javafx/8.0.171"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="rollDice.RollDiceController">
<children>
<ImageView fx:id="imageView1" fitHeight="97.0" fitWidth="94.0"
layoutX="95.0" layoutY="60.0" pickOnBounds="true"
preserveRatio="true">
<image>
<Image url="@../../../../Desktop/die1.PNG" />
</image>
</ImageView>
<ImageView fx:id="imageView2" fitHeight="89.0" fitWidth="94.0"
layoutX="355.0" layoutY="63.0" pickOnBounds="true"
preserveRatio="true">
<image>
<Image url="@../../../../Desktop/die4.PNG" />
</image>
</ImageView>
<Button layoutX="220.0" layoutY="306.0" mnemonicParsing="false"
onAction="#rollDiceOperation" prefHeight="33.0" prefWidth="82.0"
text="Roll">
<font>
<Font name="Arial Rounded MT Bold" size="24.0" />
</font>
</Button>
<Label fx:id="sum" alignment="CENTER" contentDisplay="CENTER"
layoutX="191.0" layoutY="216.0" prefHeight="51.0" prefWidth="134.0"
text="Press roll">
<font>
<Font name="Arial Rounded MT Bold" size="18.0" />
</font>
</Label>
</children>
</AnchorPane>
Output
Resources
Using JavaFX create a Roll application that implements the GUI shown When the user clicks the Rol...
Create a Roll application that implements the GUI shown in figure 1 (default images must be set as shown in figure 1). When the user clicks the Roll button, the program must roll the dice, change the figures randomly, calculate the sum of the dice and show it in a label (as shown in figure 2).
For this question you will need to complete the methods to create a JavaFX GUI application that implements two String analysis algorithms. Each algorithm is activated when its associated button is pressed. They both take their input from the text typed by the user in a TextField and they both display their output via a Text component at the bottom of the GUI, which is initialized to “Choose a string methods as indicated in the partially completed class shown after...
in JAVA please and please show output!! Create a JavaFX application that simulates the rolling of a pair of dice. When the user clicks a button, the application should generate two random numbers, each in the range of 1 through 6, to represent the value of the dice. Use ImageView component to display the dice. Six images are included in the project folder for you to use. For example, the first picture below is the initial window, after clicking the...
In JavaFX Create a GUI program shown below. User enters information through the first window. When “Close” button is clicked, your program stops, when “Show Info” button is clicked, the input information is displayed on the TextArea; while when “Modify" button is clicked, the second window pops up and the information user enters to the first window automatically fills in the second window. User can change the information on the second window. After clicking the “Change” button on the second...
Heads or Tails Create a JavaFX application that simulates a coin being tossed. When the user clicks a button, the application should generate a random number in the range of 0 to 1. If the number is 0, the coin has landed on “heads,” and if the number is 1, the coin has landed on “tails.” Use an ImageView component, and the coin images that you will find in this book’s Student Sample Programs to display the side of the...
Create a GUI or JavaFX application with two buttons and two labels. Add an Image Icon of your choice to the first button and the first label.
Write a GUI-based Java application that implements the "Math Game" shown below. The program asks the user to enter the answer of multiplying two one-digit random integers. If the user enters a correct answer, a message will be displayed at the bottom of the frame, and the text field will be cleared. If the user enters a wrong answer, a message will be displayed at the bottom of the frame asking for another answer. If the user...
Please, build calculator to exact image as below using Python. Write a GUI that implements the calculator shown in the following image: Calculator х Plus Equals: Add Clear Quit - User enters two integers into the text fields. - When Add button is pressed, the sum of the values in the text fields are shown after the Equals: as a label. - The Clear button clears the values in the text fields. The cleared values can be blank or zero....
-Write a JavaFX application that displays a Label containing the opening sentence or two from your favorite book. Save the project as FXBookQuote1a. -Add a button to the frame in the FXBookQuote program. When the user clicks the button, display the title of the book that contains the quote in a second label. Save the project as FXBookQuote1b.
1.A. Write a JavaFX application that displays a Label containing the opening sentence or two from your favorite book. Save the project as FXBookQuote1a. B. Add a button to the frame in the FXBookQuote program. When the user clicks the button, display the title of the book that contains the quote in a second label. Save the project as FXBookQuote1b.