Advertisement
rjsantiago0001

Three Random Cards

Mar 28th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. // Ricardo Santiago
  2. // 3/29/16
  3. // CS-112
  4. // HW11
  5. // This program will shuffle an ArrayList containing the values 1-54(a deck of playing cards, including jokers)
  6. // After the shuffle, the program displays the three cards associated with the values in positions 0-2 of the ArrayList
  7. // I can be reached at : rjsantiago0001@student.stcc.edu
  8.  
  9. import java.util.ArrayList;
  10. import javafx.application.Application;
  11. import javafx.scene.Scene;
  12. import javafx.scene.layout.HBox;
  13. import javafx.scene.layout.Pane;
  14. import javafx.geometry.Insets;
  15. import javafx.stage.Stage;
  16. import javafx.scene.image.Image;
  17. import javafx.scene.image.ImageView;
  18.  
  19. public class ThreeRandomCards extends Application {
  20.  
  21.     @Override // Override the start method in the Application class
  22.     public void start(Stage primaryStage) {
  23.  
  24.         ArrayList<Integer> deck = new ArrayList<>();
  25.         // start incrementing at i because card0.png does not exist in card
  26.         // directory
  27.         // increment to 54 instead of 52, so that the jokers will be included
  28.         for (int i = 1; i < 55; i++) {
  29.             deck.add(i);
  30.  
  31.         }
  32.         // shuffle the deck
  33.         java.util.Collections.shuffle(deck);
  34.  
  35.         // Create a pane to hold the image views
  36.         Pane pane = new HBox(10);
  37.         pane.setPadding(new Insets(5, 5, 5, 5));
  38.         Image image = new Image("/card/" + deck.get(0) + ".png");
  39.         pane.getChildren().add(new ImageView(image));
  40.  
  41.         ImageView imageView2 = new ImageView("/card/" + deck.get(1) + ".png");
  42.         // imageView2.setFitHeight(50);
  43.         // imageView2.setPreserveRatio(true);
  44.         // imageView2.setFitWidth(100);
  45.         pane.getChildren().add(imageView2);
  46.  
  47.         ImageView imageView3 = new ImageView("/card/" + deck.get(2) + ".png");
  48.         // imageView3.setRotate(90);
  49.         pane.getChildren().add(imageView3);
  50.  
  51.         // Create a scene and place it in the stage
  52.         Scene scene = new Scene(pane);
  53.         primaryStage.setTitle("ShowImage"); // Set the stage title
  54.         primaryStage.setScene(scene); // Place the scene in the stage
  55.         primaryStage.show(); // Display the stage
  56.     }
  57.  
  58.     /**
  59.      * The main method is only needed for the IDE with limited JavaFX support.
  60.      * Not needed for running from the command line.
  61.      */
  62.     public static void main(String[] args) {
  63.         launch(args);
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement