Advertisement
luliu

Problem 14.3 (Display 3 Cards)

Mar 24th, 2016
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None | 0 0
  1. /*
  2.  * Name: Lu Liu
  3.  * Date: 3/24/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)
  11.  */
  12.  
  13. import javafx.application.Application;
  14. import javafx.scene.Scene;
  15. import javafx.scene.layout.HBox;
  16. import javafx.scene.layout.Pane;
  17. import javafx.geometry.Insets;
  18. import javafx.stage.Stage;
  19. import javafx.scene.image.Image;
  20. import javafx.scene.image.ImageView;
  21.  
  22. public class DisplayCards extends Application {
  23.  
  24.     public void start(Stage primaryStage) {
  25.         // Create a pane to hold the image views
  26.         Pane pane = new HBox(10);
  27.         pane.setPadding(new Insets(5, 5, 5, 5));
  28.  
  29.         Image image = new Image("/image/card/" + getCard(1) + ".png");
  30.         pane.getChildren().add(new ImageView(image));
  31.  
  32.         Image image2 = new Image("image/card/" + getCard(2) + ".png");
  33.         ImageView imageView2 = new ImageView(image2);
  34.         pane.getChildren().add(imageView2);
  35.  
  36.         Image image3 = new Image("image/card/" + getCard(3) + ".png");
  37.         ImageView imageView3 = new ImageView(image3);
  38.         pane.getChildren().add(imageView3);
  39.  
  40.         // Create a scene and place it in the stage
  41.         Scene scene = new Scene(pane);
  42.         primaryStage.setTitle("Display Three Cards"); // Set the stage title
  43.         primaryStage.setScene(scene); // Place the scene in the stage
  44.         primaryStage.show(); // Display the stage
  45.     }
  46.     public static void main(String[] args) {
  47.         launch(args);
  48.     }
  49.     public static int getCard(int k) {
  50.  
  51.         int[] card = new int[52];
  52.         for (int i = 0; i < card.length; i++) {
  53.             card[i] = i;
  54.         }
  55.         for (int i = 0; i < card.length; i++) {
  56.             int j = (int) (Math.random() * card.length);
  57.             int temp = card[i];
  58.             card[i] = card[j];
  59.             card[j] = temp;
  60.         }
  61.         return card[k];
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement