luliu

Problem 14.3 (Display 3 Cards)

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