Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that displays four cards randomly selected from a deck of 52 if the Refresh button is clicked, shown below. The card image

Write a program that displays four cards randomly selected from a deck of 52 if the Refresh button is clicked, shown below. The card image files are named 1.png, 2.png 52.png and stored in the image/card directory. All four cards are distinct and selected randomly. The card files are provided in Blackboard.

Hint: You can select random cards by storing the numbers 1-52 to an array list, perform a random shuffle learned in Section 11.12, and use the first four numbers in the array list as the file names for the image. The other way is to use the static shuffle method in the java.util.Collections class, for example: java.util.Collections.shuffle(list) where list is an array list.

Directions

Create a class named CardRefreshButton extends Application.

Create a new array list, then use a for loop and add() method to add 52 cards to the list.

Revoke shuffle() method for the list to shuffle the cards.

Create an instance of HBox and add four card images by using getChildren().add() method. Make sure specify image file path and use array lists get() method to get four card image files.

Create a Button and labeled with Refresh

Create and register an event handler.

To handle event: once the button is clicked, call shuffle() method to shuffle the cards, then clear previous images by using getChildren.clear() method, and use add() to add four card images.

Create a new BorderPane to set up layout for the images and button.

Create a scene with a specific size.

Set title to Shuffling cards and display the stage.

The output should look like the screen below.

Provide appropriate Java comments.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

What are the effects of team size on performance?

Answered: 1 week ago