edu.uah.math.devices
Class Coin

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by edu.uah.math.devices.Coin
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Coin
extends javax.swing.JComponent

This class defines a coin with specified colors, value, and probability of heads. The state of the coin can be tossed or not tossed. If tossed, the coin is drawn with a color and label that depend on the outcome (heads or tails). If not tossed, the coin is shown as an outline in the background color.

Version:
August, 2003
Author:
Kyle Siegrist, Dawn Duehring
See Also:
Serialized Form

Nested Class Summary
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int HEADS
           
static java.lang.String[] labels
           
static int TAILS
           
 
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 java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Coin()
          This default constructor creates a new fair coin with a specified value, and with the default size and with head color red and tail color green.
Coin(double p)
          This special constructor creates a coin with a specified probability of heads, and with the default size 40, and with head color red and tail color green.
Coin(double p, int s)
          This special constructor creates a new coin with a specified probability and size, and with the default colors of red for heads and green for tails.
Coin(double p, int s, java.awt.Color a, java.awt.Color b, java.awt.Color c)
          This general constructor creates a new coin with a probability, preferred size, and colors.
 
Method Summary
 java.awt.Color getHeadColor()
          This method gets the head color.
 double getProbability()
          This method gets the probability of heads.
 java.awt.Color getTailColor()
          This method gets the tail color.
 java.awt.Color getTextColor()
          This method gets the text color.
 int getValue()
          This method gets the value of the coin.
 boolean isTossed()
          This method returns the state of the coin (tossed or untossed).
 void paintCoin(java.awt.Graphics2D g2, int x, int y)
           
 void paintComponent(java.awt.Graphics g)
          This method paints the coin.
 void setColors(java.awt.Color a, java.awt.Color b, java.awt.Color c)
          This method sets the colors.
 void setHeadColor(java.awt.Color c)
          This method sets the head color.
 void setProbability(double p)
          This method sets the probability of heads.
 void setTailColor(java.awt.Color c)
          This method sets the tail color.
 void setTextColor(java.awt.Color c)
          This method sets the text color.
 void setTossed(boolean b)
          This method sets the state of the coin (tossed or untossed).
 void setValue(int x)
          This method sets the coin to a specified value.
 void toss()
          This method sets the value to a random value, as determined by the probability of heads.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, 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, updateUI
 
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, imageUpdate, 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, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TAILS

public static final int TAILS
See Also:
Constant Field Values

HEADS

public static final int HEADS
See Also:
Constant Field Values

labels

public static final java.lang.String[] labels
Constructor Detail

Coin

public Coin(double p,
            int s,
            java.awt.Color a,
            java.awt.Color b,
            java.awt.Color c)
This general constructor creates a new coin with a probability, preferred size, and colors.

Parameters:
p - the probability of heads.
s - the preferred size of the coin
a - the color of the head side.
b - the color of the tail side.
c - the color of the text

Coin

public Coin(double p,
            int s)
This special constructor creates a new coin with a specified probability and size, and with the default colors of red for heads and green for tails.

Parameters:
p - the probability of heads.
s - the size of the coin.

Coin

public Coin(double p)
This special constructor creates a coin with a specified probability of heads, and with the default size 40, and with head color red and tail color green.


Coin

public Coin()
This default constructor creates a new fair coin with a specified value, and with the default size and with head color red and tail color green.

Method Detail

paintComponent

public void paintComponent(java.awt.Graphics g)
This method paints the coin.

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

paintCoin

public void paintCoin(java.awt.Graphics2D g2,
                      int x,
                      int y)

setValue

public void setValue(int x)
This method sets the coin to a specified value.

Parameters:
x - the value of the coin (0 tails, 1 heads)

getValue

public int getValue()
This method gets the value of the coin.

Returns:
the value of the coin (0 tails, 1 heads).

toss

public void toss()
This method sets the value to a random value, as determined by the probability of heads.


setTossed

public void setTossed(boolean b)
This method sets the state of the coin (tossed or untossed).

Parameters:
b - true if the coin is tossed.

isTossed

public boolean isTossed()
This method returns the state of the coin (tossed or untossed).

Returns:
true if the coin is tossed

setProbability

public void setProbability(double p)
This method sets the probability of heads.

Parameters:
p - the probability of heads.

getProbability

public double getProbability()
This method gets the probability of heads.

Returns:
the probability of heads.

setColors

public void setColors(java.awt.Color a,
                      java.awt.Color b,
                      java.awt.Color c)
This method sets the colors.

Parameters:
a - the head color.
b - the tail color.
c - the text color

setHeadColor

public void setHeadColor(java.awt.Color c)
This method sets the head color.

Parameters:
c - the head color.

getHeadColor

public java.awt.Color getHeadColor()
This method gets the head color.

Returns:
the head color.

setTailColor

public void setTailColor(java.awt.Color c)
This method sets the tail color.

Parameters:
c - the tail color.

getTailColor

public java.awt.Color getTailColor()
This method gets the tail color.

Returns:
the tail color.

setTextColor

public void setTextColor(java.awt.Color c)
This method sets the text color.

Parameters:
c - the text color.

getTextColor

public java.awt.Color getTextColor()
This method gets the text color.

Returns:
the text color.