public class Coin
extends javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent| Modifier and Type | Field and Description |
|---|---|
static int |
HEADS |
static java.lang.String[] |
labels |
static int |
TAILS |
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
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 |
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.
|
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, isPaintingOrigin, 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, updateUIadd, 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, transferFocusDownCycle, validate, validateTreeaction, 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, transferFocusBackward, transferFocusUpCyclepublic static final int TAILS
public static final int HEADS
public static final java.lang.String[] labels
public Coin(double p,
int s,
java.awt.Color a,
java.awt.Color b,
java.awt.Color c)
p - the probability of heads.s - the preferred size of the coina - the color of the head side.b - the color of the tail side.c - the color of the textpublic Coin(double p,
int s)
p - the probability of heads.s - the size of the coin.public Coin(double p)
public Coin()
public void paintComponent(java.awt.Graphics g)
paintComponent in class javax.swing.JComponentg - the graphics context.public void setValue(int x)
x - the value of the coin (0 tails, 1 heads)public int getValue()
public void toss()
public void setTossed(boolean b)
b - true if the coin is tossed.public boolean isTossed()
public void setProbability(double p)
p - the probability of heads.public double getProbability()
public void setColors(java.awt.Color a,
java.awt.Color b,
java.awt.Color c)
a - the head color.b - the tail color.c - the text colorpublic void setHeadColor(java.awt.Color c)
c - the head color.public java.awt.Color getHeadColor()
public void setTailColor(java.awt.Color c)
c - the tail color.public java.awt.Color getTailColor()
public void setTextColor(java.awt.Color c)
c - the text color.public java.awt.Color getTextColor()