Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Name: Lu Liu
- * Date: 3/24/2016
- * Course Number: CSC-112
- * Course Name: Intermediate Topics in Java Programming
- * Email: lliu0001@student.stcc.edu
- *
- * Assignment: HW # 11
- * Programe Description:
- * Problem 14.3 (Display 3 Cards)
- */
- import javafx.application.Application;
- import javafx.scene.Scene;
- import javafx.scene.layout.HBox;
- import javafx.scene.layout.Pane;
- import javafx.geometry.Insets;
- import javafx.stage.Stage;
- import javafx.scene.image.Image;
- import javafx.scene.image.ImageView;
- public class DisplayCards extends Application {
- public void start(Stage primaryStage) {
- // Create a pane to hold the image views
- Pane pane = new HBox(10);
- pane.setPadding(new Insets(5, 5, 5, 5));
- Image image = new Image("/image/card/" + getCard(1) + ".png");
- pane.getChildren().add(new ImageView(image));
- Image image2 = new Image("image/card/" + getCard(2) + ".png");
- ImageView imageView2 = new ImageView(image2);
- pane.getChildren().add(imageView2);
- Image image3 = new Image("image/card/" + getCard(3) + ".png");
- ImageView imageView3 = new ImageView(image3);
- pane.getChildren().add(imageView3);
- // Create a scene and place it in the stage
- Scene scene = new Scene(pane);
- primaryStage.setTitle("Display Three Cards"); // Set the stage title
- primaryStage.setScene(scene); // Place the scene in the stage
- primaryStage.show(); // Display the stage
- }
- public static void main(String[] args) {
- launch(args);
- }
- public static int getCard(int k) {
- int[] card = new int[52];
- for (int i = 0; i < card.length; i++) {
- card[i] = i;
- }
- for (int i = 0; i < card.length; i++) {
- int j = (int) (Math.random() * card.length);
- int temp = card[i];
- card[i] = card[j];
- card[j] = temp;
- }
- return card[k];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement