edu.uah.math.devices
Class CoinBox

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

public class CoinBox
extends javax.swing.JPanel

This class is a container that holds coins.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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
 
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
CoinBox()
          This default constructor creates a new coin box with 10 coins and with the default probability, and colors.
CoinBox(int n)
          This special constructor creates a new coin box with a specified number of coins, and with the default probability, size, and colors.
CoinBox(int n, double p)
          This special constructor creates a new coin box with a specified number of coins, and probability, and with default size 40, head color red, tail color green, and text color white
CoinBox(int n, double p, int s)
          This special constructor creates a new coin box with a specified number of coins, probability, and size, and with default head color red, tail color green, and text color white
CoinBox(int n, double p, int s, java.awt.Color a, java.awt.Color b, java.awt.Color c)
          This general constructor creates a new coin box with a specified number of coins, specified preferred size, a specified probability of heads, and specified head, tail, and text colors.
 
Method Summary
 Coin getCoin(int i)
          This method gets a specified coin.
 int getCoinCount()
          Ths method gets the number of coins.
 java.awt.Color getHeadColor()
          This method returns the head color.
 int getHeadCount()
          This method returns the number of heads
 double getProbability()
          This method returns the probability of heads.
 java.awt.Color getTailColor()
          This method returns the tail color.
 int getTailCount()
          This method returns the number of tails
 java.awt.Color getTextColor()
          This method returns the tail color.
 int[] getValues()
          This method returns the array of values.
 int getValues(int i)
          This method returns the value of an individual coin
 boolean isTossed()
          This method returns the state of the all of the coins (tossed or untossed).
 void setCoinCount(int n)
          This method sets the number of coins.
 void setColors(java.awt.Color a, java.awt.Color b, java.awt.Color c)
          This method sets the colors for all of the coins.
 void setHeadColor(java.awt.Color c)
          This method sets the head color for all of the coins.
 void setProbability(double p)
          This method sets the probability of heads for all of the coins.
 void setTailColor(java.awt.Color c)
          This method sets the tail color for all of the coins.
 void setTextColor(java.awt.Color c)
          This method sets the text color for all of the coins.
 void setTossed(boolean b)
          This method sets the state of the all of the coins (tossed or untossed).
 void setValues(int[] v)
          This method sets the array of values.
 void setValues(int i, int x)
          This method sets the value of an individual coin.
 void toss()
          This method tosses the coins, setting them to random values, as determined by the probability of heads for each coin.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, 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, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, 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
 

Constructor Detail

CoinBox

public CoinBox(int n,
               double p,
               int s,
               java.awt.Color a,
               java.awt.Color b,
               java.awt.Color c)
This general constructor creates a new coin box with a specified number of coins, specified preferred size, a specified probability of heads, and specified head, tail, and text colors.

Parameters:
n - the number of coins.
p - the probability of heads
s - the preferred size
a - the head color.
b - the tail color.
c - the text color

CoinBox

public CoinBox(int n,
               double p,
               int s)
This special constructor creates a new coin box with a specified number of coins, probability, and size, and with default head color red, tail color green, and text color white

Parameters:
n - the number of coins.
p - the probability of heads
s - the preferred size.

CoinBox

public CoinBox(int n,
               double p)
This special constructor creates a new coin box with a specified number of coins, and probability, and with default size 40, head color red, tail color green, and text color white

Parameters:
n - the number of coins.
p - the probability of heads

CoinBox

public CoinBox(int n)
This special constructor creates a new coin box with a specified number of coins, and with the default probability, size, and colors.

Parameters:
n - the number of coins.

CoinBox

public CoinBox()
This default constructor creates a new coin box with 10 coins and with the default probability, and colors.

Method Detail

getCoinCount

public int getCoinCount()
Ths method gets the number of coins.

Returns:
the number of coins.

setCoinCount

public void setCoinCount(int n)
This method sets the number of coins. If the new coin count is greater than the old, an appropriate number of new coins are added. If the new coin count is smaller than the old, an appropriate number of coins are removed. The coin count is then updated.

Parameters:
n - the number of coins in the coin box

getCoin

public Coin getCoin(int i)
This method gets a specified coin.

Parameters:
i - the index of the coin.
Returns:
the coin.

setProbability

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

Parameters:
p - the probability of heads.

getProbability

public double getProbability()
This method returns 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 for all of the coins.

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 for all of the coins.

Parameters:
c - the head color

getHeadColor

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

Returns:
the head color

setTailColor

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

Parameters:
c - the tail color

getTailColor

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

Returns:
the tail color

setTextColor

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

Parameters:
c - the text color

getTextColor

public java.awt.Color getTextColor()
This method returns the tail color.

Returns:
the text color

toss

public void toss()
This method tosses the coins, setting them to random values, as determined by the probability of heads for each coin.


getHeadCount

public int getHeadCount()
This method returns the number of heads

Returns:
the number of heads.

getTailCount

public int getTailCount()
This method returns the number of tails

Returns:
the number of tails.

setTossed

public void setTossed(boolean b)
This method sets the state of the all of the coins (tossed or untossed). Tossed coins are shown with a label and color that depend on the outcome. Untossed coins are shown unlabeled in the background color.

Parameters:
b - true if the coins are tossed.

isTossed

public boolean isTossed()
This method returns the state of the all of the coins (tossed or untossed). Tossed coins are shown with a label and color that depend on the outcome. Untossed coins are shown unlabeled in the background color.

Returns:
true if the coins are tossed.

setValues

public void setValues(int[] v)
This method sets the array of values.

Parameters:
v - the array of values

getValues

public int[] getValues()
This method returns the array of values.

Returns:
the array of values

setValues

public void setValues(int i,
                      int x)
This method sets the value of an individual coin.

Parameters:
i - the index
x - the value of the coin

getValues

public int getValues(int i)
This method returns the value of an individual coin

Parameters:
i - the index
Returns:
the value of the coin with the index