Advertisement
luliu

Problem 14.3 (Display 3 Cards) V2

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