Advertisement
prprice16

Card

Oct 14th, 2020
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import javax.swing.ImageIcon;
  2.  
  3. public class Card
  4. {
  5.     //for portability
  6.     final static String sep = java.io.File.separator;
  7.        
  8.     //same back image for every card
  9.     private static final ImageIcon cardBackImage =
  10.                 new ImageIcon("cards" + sep + "b.gif");
  11.     //attributes of a card
  12.     private String rank; // face of card ("Ace", "Deuce", ...)
  13.     private  String suit; // suit of card ("Hearts", "Diamonds", ...)
  14.     private  int value;
  15.     private ImageIcon image;
  16.  
  17.     //default constructor
  18.     public Card()
  19.     {
  20.         //System.out.println("Default Card constructor called");
  21.         rank = "none";
  22.         suit = "none";
  23.         value = 0;
  24.     }
  25.     // two-argument constructor initializes card's face and suit
  26.     public Card(String r, String s, int v, String pic)
  27.     {
  28.         rank = r;
  29.         suit = s;
  30.         value = v;
  31.         image = new ImageIcon(pic);
  32.         //setIcon method changes pic in JLabel
  33.      }
  34.        
  35.  
  36.      public int getValue()
  37.      {
  38.         return value;
  39.      }
  40.        
  41.  
  42.      public ImageIcon getImage(boolean faceup)
  43.      {
  44.          if (faceup)
  45.              return image;
  46.          else
  47.              return cardBackImage;
  48.      }
  49.  
  50.      // return String representation of Card
  51.      public String toString()
  52.      {
  53.         return rank + " of " + suit;
  54.      }
  55.  
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement