Advertisement
luliu

Problem 14.3 (Display 3 Cards) V2

Mar 26th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * Name: Lu Liu
  3.  * Date: 3/26/2016
  4.  * Course Number: CSC-112
  5.  * Course Name: Intermediate Topics in Java Programming
  6.  * Email: lliu0001@student.stcc.edu
  7.  *
  8.  * Assignment: HW # 11
  9.  * Programe Description:
  10.  * Problem 14.3 (Display 3 Cards) V2
  11.  */
  12.  
  13. package myJavaFx;
  14.  
  15. import javafx.application.Application;
  16. import javafx.scene.Scene;
  17. import javafx.scene.layout.HBox;
  18. import javafx.scene.layout.Pane;
  19. import javafx.geometry.Insets;
  20. import javafx.stage.Stage;
  21. import javafx.scene.image.Image;
  22. import javafx.scene.image.ImageView;
  23.  
  24. public class DisplayCards extends Application {
  25.  
  26.     public void start(Stage primaryStage) {
  27.  
  28.         // Create a array hold the first three number of the card
  29.         int[] threeCard = new int[3];
  30.         for (int i = 0; i < 3; i++) {
  31.             threeCard[i] = getCard()[i];
  32.         }
  33.  
  34.         // Create a pane to hold the image views
  35.         Pane pane = new HBox(10);
  36.         pane.setPadding(new Insets(5, 5, 5, 5));
  37.         Image image = new Image("/image/card/" + threeCard[0] + ".png");
  38.         pane.getChildren().add(new ImageView(image));
  39.  
  40.         Image image2 = new Image("image/card/" + threeCard[1] + ".png");
  41.         ImageView imageView2 = new ImageView(image2);
  42.         pane.getChildren().add(imageView2);
  43.  
  44.         Image image3 = new Image("image/card/" + threeCard[2] + ".png");
  45.         ImageView imageView3 = new ImageView(image3);
  46.         pane.getChildren().add(imageView3);
  47.  
  48.         // Create a scene and place it in the stage
  49.         Scene scene = new Scene(pane);
  50.         primaryStage.setTitle("Display Three Cards"); // Set the stage title
  51.         primaryStage.setScene(scene); // Place the scene in the stage
  52.         primaryStage.show(); // Display the stage
  53.     }
  54.  
  55.     public static void main(String[] args) {
  56.         launch(args);
  57.     }
  58.  
  59.     // Get the card array and shuffle them
  60.     public static int[] getCard() {
  61.  
  62.         int[] card = new int[52];
  63.         for (int i = 0; i < card.length; i++) {
  64.             card[i] = i + 1;
  65.         }
  66.         for (int i = 0; i < card.length; i++) {
  67.             int j = (int) (Math.random() * card.length);
  68.             int temp = card[i];
  69.             card[i] = card[j];
  70.             card[j] = temp;
  71.         }
  72.         return card;
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement