Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a folder of images (gifs) that I want to access in my program, but I don\

ID: 3774538 • Letter: I

Question

I have a folder of images (gifs) that I want to access in my program, but I don't know how to implent that. I'm making a poker game and when I run it, I should be able to see the cards in my hand. I've tried dragging the folder into Eclipse, but nothing happened. This is part of my Card class:

public class Card implements Comparable<Card>{

   private Suit suitValue;

   private Rank rankValue;

   private ImageIcon cardImage;

   private static boolean sortRankMajorOrder = true;

      /**

   * Creates a new playing card.

   * @param suit the suit value of this card.

   * @param rank the rank value of this card.

   * @param cardFace the face image of this card.

   */

   public Card(Suit suit, Rank rank, ImageIcon cardFace) {

      cardImage = cardFace;

      suitValue = suit;

      rankValue = rank;

   }

  

  

      /**

   * Generates the filename associated with the card. <code>getFilename</code> assumes that all of the standard card images

   * are stored in individual files using filenames in the form of:

   * <b>RS.gif</b> where <b>R</b> is a single character used to represent

   * the rank value of the card and <b>S</b> is a single character used to represent

   * the suit value of the card.

   * <p>The characters used for <b>R</b> are:

   * 'a' (ace), '2', '3', '4', '5', '6', '7', '8', '9',

   * 't' (10), 'j' (jack), 'q' (queen), and 'k' (king).

   * <p>The characters used for <b>S</b> are:

   * 'c' (clubs), 'd' (diamonds), 'h' (hearts), and 's' (spades).

   * <p>Two other cards are also available: "b.gif" (back of card) and "j.gif" (joker).

   *

   * @param suit the suit value of the card.

   * @param rank the rank value of the card.

   * @return a string containing the filename of the card.

   */

   public static String getFilename(Suit suit, Rank rank) {

      return rank.getSymbol() + suit.getSymbol() + ".gif";

   }

Explanation / Answer

So you say you have a folder....

You can do this:

For the images you can use some Collection to load them in.

I take the assumption that you can work out the loadImage(File file) method. And if you have other files then images in that folder you better read up on FileFilter.