|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Card
Representation of a single playing card. A card consists of a suit value (e.g. hearts, spades), a rank value (e.g. ace, 7, king), and an image of the front of the card. A card object is immutable; once instantiated, the values cannot change.
Constructor Summary | |
Card(Suit suit,
Rank rank,
javax.swing.ImageIcon cardFace)
Creates a new playing card. |
Method Summary | |
int |
compareTo(java.lang.Object otherCardObject)
Compares two cards for the purposes of sorting. |
javax.swing.ImageIcon |
getCardImage()
Returns the graphic image of the card. |
static java.lang.String |
getFilename(Suit suit,
Rank rank)
Generates the filename associated with the card. |
Rank |
getRank()
Returns the rank of the card. |
Suit |
getSuit()
Returns the suit of the card. |
boolean |
isSameAs(Card card)
Compares two cards to determine if they have the same value. |
java.lang.String |
rankToString()
Returns a description of the rank of this card. |
static void |
setRankMajorSort()
Specifies that cards are to be sorted in rank-major order. |
static void |
setSuitMajorSort()
Specifies that cards are to be sorted in suit-major order. |
java.lang.String |
suitToString()
Returns a description of the suit of this card. |
java.lang.String |
toString()
Returns a description of this card. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Card(Suit suit, Rank rank, javax.swing.ImageIcon cardFace)
suit
- the suit value of this card.rank
- the rank value of this card.cardFace
- the face image of this card.Method Detail |
public static java.lang.String getFilename(Suit suit, Rank rank)
getFilename
assumes that all of the standard card images
are stored in individual files using filenames in the form of:
RS.gif where R is a single character used to represent
the rank value of the card and S is a single character used to represent
the suit value of the card.
The characters used for R are: 'a' (ace), '2', '3', '4', '5', '6', '7', '8', '9', 't' (10), 'j' (jack), 'q' (queen), and 'k' (king).
The characters used for S are: 'c' (clubs), 'd' (diamonds), 'h' (hearts), and 's' (spades).
Two other cards are also available: "b.gif" (back of card) and "j.gif" (joker).
suit
- the suit value of the card.rank
- the rank value of the card.public Suit getSuit()
public Rank getRank()
public javax.swing.ImageIcon getCardImage()
public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String rankToString()
public java.lang.String suitToString()
public static void setRankMajorSort()
public static void setSuitMajorSort()
public int compareTo(java.lang.Object otherCardObject)
compareTo
in interface java.lang.Comparable
otherCardObject
- the other cardpublic boolean isSameAs(Card card)
equals
which compares
two objects for equality.card
- the other cardtrue
if the two cards have the same rank and suit
values, false
if they do not.
|
|||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |