import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.control.Labeled; import javafx.scene.control.TextField; import javafx.scene.image.ImageView; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.text.Text; import javafx.stage.Stage; import javafx.geometry.Insets; import javafx.scene.image.Image; import javafx.scene.layout.GridPane; import java.util.Random; import javafx.event.ActionEvent; import javafx.event.EventHandler; public class Test_4 extends Application { Button button; TextField amount; Label amountEntered, totalWinnings, spinWinnings, label; public static void main(String[] args) { launch(args); } @Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("Slot Machine"); //Total int total = 0; //Text TextField amount; amount = new TextField(); amount.setTranslateX(0); amount.setTranslateY(195); amount.setMinWidth(50); String input = amount.getText(); //Button Layout button = new Button(); button.setText("Spin to win!"); button.setTranslateX(0); button.setTranslateY(200); button.setOnAction(e -> { }); //Label Label amountEntered, totalWinnings, spinWinnings; amountEntered = new Label("Amount Entered "); amountEntered.setTranslateX(0); amountEntered.setTranslateY(100); spinWinnings = new Label("The amount won from this spin: "); spinWinnings.setTranslateX(150); spinWinnings.setTranslateY(73); totalWinnings = new Label("The total amount won: "); totalWinnings.setTranslateX(375); totalWinnings.setTranslateY(47); //Image Random random = new Random(); String[] images = new String[]{"pictures/1.bmp", "pictures/2.bmp", "pictures/3.bmp","pictures/4.bmp", "pictures/5.bmp"}; int index = (int) (Math.random() * (images.length - 1)); ImageView MyImage1 = new ImageView(images[index]); int index2 = (int) (Math.random() * (images.length - 1)); ImageView MyImage2 = new ImageView(images[index2]); int index3 = (int) (Math.random() * (images.length - 1)); ImageView MyImage3 = new ImageView(images[index3]); MyImage1.setTranslateX(0); MyImage1.setTranslateY(-150); MyImage2.setTranslateX(125); MyImage2.setTranslateY(-288); MyImage3.setTranslateX(250); MyImage3.setTranslateY(-426); //layout VBox layout = new VBox(10); layout.setPadding(new Insets(20, 20, 20, 20)); layout.getChildren().addAll(amount, button, amountEntered, spinWinnings, totalWinnings, MyImage1, MyImage2, MyImage3); button.setOnAction(new EventHandler(){ @Override public void handle(ActionEvent event) { String[] images = new String[]{"pictures/1.bmp", "pictures/2.bmp", "pictures/3.bmp","pictures/4.bmp", "pictures/5.bmp"}; int index = (int) (Math.random() * (images.length - 1)); MyImage1.setImage(new Image(images[index])); int index2 = (int) (Math.random() * (images.length - 1)); MyImage2.setImage(new Image(images[index2])); int index3 = (int) (Math.random() * (images.length - 1)); MyImage3.setImage(new Image(images[index3])); int spinAmount = 0; int total = 0; if (index == index2 && index == index3) { spinAmount = spinAmount * 3; } else if (index == index2 || index == index3 || index2==index3) { spinAmount = spinAmount * 2; } else spinAmount = 0; total = total + spinAmount; } }); //Scene Layout Scene scene = new Scene(layout, 600, 300); primaryStage.setScene(scene); primaryStage.show(); } }