Question
Assignment 4 - GUI Cards Goals In this assignment, we will be designing a program using JavaFX Instructions Hand in only one program, please. A
Assignment 4 - GUI Cards
Goals
In this assignment, we will be designing a program using JavaFX
Instructions
Hand in only one program, please.
A Scene of Card Images
Understand the Classes and Problem
We wish to move our CardIdentity and Card classes from the realm of console apps to that of GUI apps. We'll do this in stages.
Read and display Card pictures - Read .gif image files as Images, and attach them to an ImageView that we can display on a Pane.
Encapsulate the Card Images in a class GUICard - Once we debug imagery for cards, above, we can move it into its own class, GUICard.
Create a CardTable class - This Scene class will embody the Pane and Layout(s) needed for our application. This is where all the cards and controls will be placed.
The first phase (item 1) will allow you to debug the problem of reading the .gif files and displaying them on a Pane without any excess logic or class complexity. The second phase (items 2 and 3) will let you turn what you did in the first phase and what you read in the chapter into a multi-class project.
The three bullets will be done in two phases. The main, public class of each program must be named Foothill so I can easily run it, and other classes must not be public. You do not submit any runs - I will run your programs.
Download the Card .gifs
The GNU Free Software Foundation provides code and images for playing-cards that are public domain. I prepared a .zip file which contains a .gif for every card with some minor name changes. Download it here:
Card Images Download .
After you unzip them, you will have a single folder called images that contains all the .gif files. Move that folder to your [java workspace]/[project name] directory. If your project is named Assignment_4, and your Eclipse workspace is named workspace, then move images folder to workspace/Assignment_4. Since your program considers Assignment_4 to be the root directory, all .gif files can be referenced from your program using names like "images/3S.gif" for, say, 3 of spades.
In addition to the 52 standard cards, there are four jokers and a card-back image which can be used to display dealer or other player cards that you don't want the user to see yet.
(The card on the far right is joker 2, not a jack.)
Phase 1: Reading and Displaying the .gif Files
In section 14.9 of our book, you learned how to instantiate an Image object to represent any .gif, .jpg or other image file on your disk and then place that Image on a ImageView. In Phase 1, we simply create an array of 57 ImageViews, attach the 57 .gif files to them, and display the labels, unstructured, in a single Pane. Here is a possible start() that you can use as a starting point. You don't have to use my main() but yours should be no longer or more complicated. Look at your images folder to see the names of each .gif file: you have to be able to construct their names in a loop (-20 points if you list all 52 cards named literally because this is array logic). Where is the card-back image stored? Find it in the images folder. **If you have issues, try adding a "file:" in front, so it became "file:images/" and that should help.**
import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.layout.*; import javafx.geometry.Insets; import javafx.stage.Stage; import javafx.scene.image.*; import javafx.scene.control.Label; public class Foothill extends Application { // static for the 57 images and their corresponding labels // normally we would not have a separate label for each card, but // if we want to display all at once using labels, we need to. static final int NUM_CARD_IMAGES = 57; // 52 + 4 jokers + 1 back-of-card image static Pane pane = new FlowPane(); static Image[] image = new Image[NUM_CARD_IMAGES]; static ImageView[] views = new ImageView[NUM_CARD_IMAGES]; // for assisting with conversions: static String cardlValsConvertAssist = "23456789TJQKAX"; static String suitValsConvertAssist = "CDHS"; public static void main(String[] args) { launch(args); } public void start(Stage primaryStage) { // prepare the image array loadCardImages(); // Create the scene and place it in the stage Scene scene = new Scene(pane, 800, 600); primaryStage.setTitle("Card Room"); primaryStage.setScene(scene); // show everything to the user primaryStage.show(); } static void loadCardImages() { String imageFileName; int intSuit, intVal; for (intSuit = 0; intSuit < 4; intSuit++) for (intVal = 0; intVal < 14; intVal++ ) { // card image files stored in Foothill/images folder with names like // "AC.gif", "3H.gif","XD.gif", etc. // This is all you need to figure out for Phase 1. } imageFileName = "images/BK.gif"; image[image.length - 1] = new Image(imageFileName); views[image.length - 1] = new ImageView(image[image.length - 1]); pane.getChildren().add(views[image.length - 1]); } // turns 0 - 13 into 'A', '2', '3', ... 'Q', 'K', 'X' static char turnIntIntoCardValueChar(int k) { if ( k < 0 || k > 13) return '?'; return cardlValsConvertAssist.charAt(k); } // turns 0 - 3 into 'C', 'D', 'H', 'S' static char turnIntIntoCardSuitChar(int k) { if ( k < 0 || k > 3) return '?'; return suitValsConvertAssist.charAt(k); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started