edu.gvsu
Class GVcard

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JLabel
                  extended by edu.gvsu.GVcard
All Implemented Interfaces:
java.awt.datatransfer.Transferable, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.SwingConstants

public class GVcard
extends javax.swing.JLabel
implements java.awt.datatransfer.Transferable

This is an abstraction of a single card. This class is implemented as a subclass of JLabel. You are unlikely to use this class directly for the project. Use the Pile class instead. Use the getValue() method to get the integer value of a card (Ace=14, King=13, Queen=12, Jack=11). Use the getSuit() method to get the integer representation of the suit (Diamond=0, Heart=1, Spade=2, Club=3). If you need to obtain the String name of the suit, use the getSuitName() method.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JLabel
javax.swing.JLabel.AccessibleJLabel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int ACE
          constant definition for Ace
static int CLUB
          constant definition for Club
static int DIAMOND
          constant definition for Diamond
static int HEART
          constant definition for Heart
static int JACK
          constant definition for Jack
static int KING
          constant definition for King
static int QUEEN
          constant definition for Queen
static int SPADE
          constant definition for Spade
 
Fields inherited from class javax.swing.JLabel
labelFor
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
GVcard(int value, int suit, javax.swing.ImageIcon img)
          Constructor, similar to the previous constructor but the front face image is an Icon object.
GVcard(int value, int suit, java.lang.String img_file)
          Constructor.
 
Method Summary
 void faceDown()
          Make the card to face down
 void faceUp()
          Make the card to face up
 void flip()
          Flip the card
static int getCardHeight()
          Returns the height of a card
static int getCardWidth()
          Returns the width of a card
 java.awt.Dimension getMaximumSize()
          Override the method in the parent class
 java.awt.Dimension getMinimumSize()
          Override the method in the parent class
 java.awt.Dimension getPreferredSize()
          Override the method in the parent class
 int getSuit()
          Get the suit of the card
 java.lang.String getSuitName()
          Get the name of the suit
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor f)
           
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
           
 int getValue()
          Get the numerical value of the card
 boolean isBlack()
          Check if the card is from a black suit (CLUB or SPADE)
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor f)
           
 boolean isDown()
          Check if the card is facing down
 boolean isMarked()
          Check if the card has been marked
 boolean isRed()
          Check if the card is from a red suit (DIAMOND or HEART)
 boolean isUp()
          Check if the card is facing up
 void mark()
          Mark the card by changing its front face to a "grayscale" image
 void paintComponent(java.awt.Graphics g)
          Override the paintComponent() method
static void setBackFace(java.lang.String img_file)
          Set the image (PNG, JPEG, GIF) image of the back of the card
 java.lang.String toString()
          Override the method in the parent class
 void unMark()
          Unmark the card by restoring its front face image
 
Methods inherited from class javax.swing.JLabel
checkHorizontalKey, checkVerticalKey, getAccessibleContext, getDisabledIcon, getDisplayedMnemonic, getDisplayedMnemonicIndex, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getLabelFor, getText, getUI, getUIClassID, getVerticalAlignment, getVerticalTextPosition, imageUpdate, paramString, setDisabledIcon, setDisplayedMnemonic, setDisplayedMnemonic, setDisplayedMnemonicIndex, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabelFor, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

JACK

public static final int JACK
constant definition for Jack

See Also:
Constant Field Values

QUEEN

public static final int QUEEN
constant definition for Queen

See Also:
Constant Field Values

KING

public static final int KING
constant definition for King

See Also:
Constant Field Values

ACE

public static final int ACE
constant definition for Ace

See Also:
Constant Field Values

DIAMOND

public static final int DIAMOND
constant definition for Diamond

See Also:
Constant Field Values

HEART

public static final int HEART
constant definition for Heart

See Also:
Constant Field Values

SPADE

public static final int SPADE
constant definition for Spade

See Also:
Constant Field Values

CLUB

public static final int CLUB
constant definition for Club

See Also:
Constant Field Values
Constructor Detail

GVcard

public GVcard(int value,
              int suit,
              java.lang.String img_file)
Constructor.

Parameters:
value - integer value of the card (2, 3, ..., 10, JACK, ..., ACE .
suit - integer value representing the suit of the card (HEART, SPADE, CLUB, DIAMOND).
img_file - a JPEG or GIF image to be used for the front face of the card.

GVcard

public GVcard(int value,
              int suit,
              javax.swing.ImageIcon img)
Constructor, similar to the previous constructor but the front face image is an Icon object.

Parameters:
value - integer value of the card (2, 3, ..., 10, JACK, ..., ACE .
suit - integer value representing the suit of the card (HEART, SPADE, CLUB, DIAMOND).
img - an ImageIcon containing the front face of the card.
Method Detail

paintComponent

public void paintComponent(java.awt.Graphics g)
Override the paintComponent() method

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - graphics context

setBackFace

public static void setBackFace(java.lang.String img_file)
Set the image (PNG, JPEG, GIF) image of the back of the card

Parameters:
img_file - a JPEG or GIF image to be used for the front face of the card.

getCardWidth

public static int getCardWidth()
Returns the width of a card

Returns:
width (in pixels)

getCardHeight

public static int getCardHeight()
Returns the height of a card

Returns:
height (in pixels)

mark

public void mark()
Mark the card by changing its front face to a "grayscale" image


unMark

public void unMark()
Unmark the card by restoring its front face image


isMarked

public boolean isMarked()
Check if the card has been marked

Returns:
true if the card has been marked, false otherwise.

isUp

public boolean isUp()
Check if the card is facing up

Returns:
true/false

isDown

public boolean isDown()
Check if the card is facing down

Returns:
true/false

isRed

public boolean isRed()
Check if the card is from a red suit (DIAMOND or HEART)

Returns:
true/false

isBlack

public boolean isBlack()
Check if the card is from a black suit (CLUB or SPADE)

Returns:
true/false

getValue

public int getValue()
Get the numerical value of the card

Returns:
numerical value of the card (2-14)

getSuit

public int getSuit()
Get the suit of the card

Returns:
numerical value of the suit (CLUB, SPADE, HEART, DIAMOND)

getSuitName

public java.lang.String getSuitName()
Get the name of the suit

Returns:
the name of the suit as a String

faceUp

public void faceUp()
Make the card to face up


faceDown

public void faceDown()
Make the card to face down


flip

public void flip()
Flip the card


getPreferredSize

public java.awt.Dimension getPreferredSize()
Override the method in the parent class

Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Override the method in the parent class

Overrides:
getMinimumSize in class javax.swing.JComponent

getMaximumSize

public java.awt.Dimension getMaximumSize()
Override the method in the parent class

Overrides:
getMaximumSize in class javax.swing.JComponent

toString

public java.lang.String toString()
Override the method in the parent class

Overrides:
toString in class java.awt.Component

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor f)
                                 throws java.awt.datatransfer.UnsupportedFlavorException
Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Throws:
java.awt.datatransfer.UnsupportedFlavorException

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor f)
Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable