Advertisement
luliu

Problem 14.3 (Display 3 Cards) V3

Mar 28th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. /*
  2. * Name: Lu Liu
  3. * Date: 3/28/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 V3
  9. * Programe Description:
  10. * Problem 14.3 (Display 3 Cards)V3
  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[] deck = getCard();
  30. int[] threeCard = new int[3];
  31. for (int i = 0; i < 3; i++) {
  32. threeCard[i] = deck[i];
  33. }
  34.  
  35.  
  36. // Create a pane to hold the image views
  37. Pane pane = new HBox(10);
  38. pane.setPadding(new Insets(5, 5, 5, 5));
  39. Image image = new Image("/image/card/" + threeCard[0] + ".png");
  40. pane.getChildren().add(new ImageView(image));
  41.  
  42. Image image2 = new Image("image/card/" + threeCard[1] + ".png");
  43. ImageView imageView2 = new ImageView(image2);
  44. pane.getChildren().add(imageView2);
  45.  
  46. Image image3 = new Image("image/card/" + threeCard[2] + ".png");
  47. ImageView imageView3 = new ImageView(image3);
  48. pane.getChildren().add(imageView3);
  49.  
  50. // Create a scene and place it in the stage
  51. Scene scene = new Scene(pane);
  52. primaryStage.setTitle("Display Three Cards"); // Set the stage title
  53. primaryStage.setScene(scene); // Place the scene in the stage
  54. primaryStage.show(); // Display the stage
  55. }
  56.  
  57. public static void main(String[] args) {
  58. launch(args);
  59. }
  60.  
  61. // Get the card array and shuffle them
  62. public static int[] getCard() {
  63.  
  64. int[] card = new int[52];
  65. for (int i = 0; i < card.length; i++) {
  66. card[i] = i + 1;
  67. }
  68. for (int i = 0; i < card.length; i++) {
  69. int j = (int) (Math.random() * card.length);
  70. int temp = card[i];
  71. card[i] = card[j];
  72. card[j] = temp;
  73. }
  74. return card;
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement