Question: ( Pick four cards ) Write a program that lets the user click the Refresh button to display four cards from a deck of 52
(Pick four cards) Write a program that lets the user click the Refresh button to display four cards from a deck of 52 cards, as shown in Figure 15.24a. (See the hint in Programming Exercise 14.3 on how to obtain four random cards.) Please add onto the current code given, to prompt a refresh button.
import java.util.List;
import java.util.Arrays;
import java.util.ArrayList;
import javafx.stage.Stage;
import javafx.geometry.HPos;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Pane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.application.Application;
public class Cards extends Application {
@Override
public void start (Stage primaryStage)
{
Integer[] cardArray = new Integer [52];
for (int i =0; i cardArray[i]=i; ArrayList // begin action java.util.Collections.shuffle(list); Pane pane = new HBox(10); pane.setPadding(new Insets(5, 5, 5, 5)); Image card1 = new Image(list.get(0)+".png"); pane.getChildren().add(new ImageView(card1)); Image card2 = new Image(list.get(1)+".png"); pane.getChildren().add(new ImageView(card2)); Image card3 = new Image(list.get(2)+".png"); pane.getChildren().add(new ImageView(card3)); Scene scene = new Scene(pane); primaryStage.setTitle("Show Image"); primaryStage.setScene(scene); primaryStage.show(); // end action } public static void main(String[] args) { // TODO Auto-generated method stub { launch(args); } } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
