SHOW:
|
|
- or go back to the newest paste.
1 | /* | |
2 | * Name: Lu Liu | |
3 | - | * Date: 3/24/2016 |
3 | + | * Date: 3/26/2016 |
4 | * Course Number: CSC-112 | |
5 | * Course Name: Intermediate Topics in Java Programming | |
6 | * Email: [email protected] | |
7 | * | |
8 | * Assignment: HW # 11 | |
9 | * Programe Description: | |
10 | - | * Problem 14.3 (Display 3 Cards) |
10 | + | * Problem 14.3 (Display 3 Cards) V2 |
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 | - | Image image = new Image("/image/card/" + getCard(1) + ".png"); |
29 | + | int[] threeCard = new int[3]; |
30 | for (int i = 0; i < 3; i++) { | |
31 | threeCard[i] = getCard()[i]; | |
32 | - | Image image2 = new Image("image/card/" + getCard(2) + ".png"); |
32 | + | |
33 | ||
34 | // Create a pane to hold the image views | |
35 | Pane pane = new HBox(10); | |
36 | - | Image image3 = new Image("image/card/" + getCard(3) + ".png"); |
36 | + | |
37 | Image image = new Image("/image/card/" + threeCard[0] + ".png"); | |
38 | pane.getChildren().add(new ImageView(image)); | |
39 | ||
40 | Image image2 = new Image("image/card/" + threeCard[1] + ".png"); | |
41 | ImageView imageView2 = new ImageView(image2); | |
42 | pane.getChildren().add(imageView2); | |
43 | ||
44 | Image image3 = new Image("image/card/" + threeCard[2] + ".png"); | |
45 | ImageView imageView3 = new ImageView(image3); | |
46 | pane.getChildren().add(imageView3); | |
47 | ||
48 | // Create a scene and place it in the stage | |
49 | - | public static int getCard(int k) { |
49 | + | |
50 | primaryStage.setTitle("Display Three Cards"); // Set the stage title | |
51 | primaryStage.setScene(scene); // Place the scene in the stage | |
52 | primaryStage.show(); // Display the stage | |
53 | - | card[i] = i; |
53 | + | |
54 | ||
55 | public static void main(String[] args) { | |
56 | launch(args); | |
57 | } | |
58 | ||
59 | // Get the card array and shuffle them | |
60 | public static int[] getCard() { | |
61 | - | return card[k]; |
61 | + | |
62 | int[] card = new int[52]; | |
63 | for (int i = 0; i < card.length; i++) { | |
64 | card[i] = i + 1; | |
65 | } | |
66 | for (int i = 0; i < card.length; i++) { | |
67 | int j = (int) (Math.random() * card.length); | |
68 | int temp = card[i]; | |
69 | card[i] = card[j]; | |
70 | card[j] = temp; | |
71 | } | |
72 | return card; | |
73 | } | |
74 | } |