|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel edu.uah.math.devices.Graph edu.uah.math.devices.GaltonBoard
public class GaltonBoard
This class is a simple model of the classical Galton board. A ball falls through a triangular array of pegs. At each peg, the ball may bounce to the right or to the left. This class can be used to illustrate Bernoulli trials and various combinatorial formulas.
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 edu.uah.math.devices.Graph |
---|
ABOVE, BELOW, HORIZONTAL, LEFT, RIGHT, showModelDistribution, VERTICAL |
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 | |
---|---|
GaltonBoard()
This default constructor creates a new Galton board with 10 rows and with the dafult probabilities and colors. |
|
GaltonBoard(int n)
This special constructor creates a new Galton board with a specified number of rows, and with default probability 0.5, and default peg color blue and ball color red. |
|
GaltonBoard(int n,
double p)
This special constructor creates a new Galton board with a specified number of rows, a specified probability, and with default peg color blue and ball color red. |
|
GaltonBoard(int n,
double p,
java.awt.Color pc,
java.awt.Color bc)
This general constructor creates a new Galton board with a specified number for the last row, a specified probability, and specified ball and peg colors. |
Method Summary | |
---|---|
void |
drawBall(int x,
int y)
This method draws the ball at a specified peg. |
java.awt.Color |
getBallColor()
This method returns the ball color. |
int |
getBallColumn()
This method returns the column number of the ball (an integer between 0 and the row number of the ball). |
int |
getBallRow()
This method returns the row number of the ball (an integer between 0 and the number of rows); |
java.lang.String |
getBitString()
This method returns the bit string that corresponds to the path of the ball through the Galton board, up to the current ball location. |
java.awt.Color |
getPegColor()
This method returns the peg color. |
double |
getProbability()
This method returns the probability of a step to the right. |
double |
getRadius()
This method returns the radius of the pegs and the ball. |
int |
getRows()
This method returns the number of rows. |
java.lang.String |
getSubset()
This method returns the subset of {1, 2, ..., n} (where n is the number of rows) that corresponds to the path of the ball through the Galton board, up to the current ball location. |
boolean |
isPathDrawn()
This method returns the path drawn boolean variable. |
void |
mouseDragged(java.awt.event.MouseEvent event)
|
void |
mouseEntered(java.awt.event.MouseEvent event)
|
void |
mouseExited(java.awt.event.MouseEvent event)
|
void |
mouseMoved(java.awt.event.MouseEvent e)
This method handles the mouse move event. |
void |
mousePressed(java.awt.event.MouseEvent event)
|
void |
mouseReleased(java.awt.event.MouseEvent event)
|
int |
moveBall()
This method moves the ball randomly to the next row, according to the probability. |
void |
moveBall(int i)
This method moves the ball to a specified position on the next row. |
void |
paintComponent(java.awt.Graphics g)
This method draws the Galton board. |
void |
reset()
This method resets the Galton board, including the path, bit string, and subset. |
void |
setBallColor(java.awt.Color c)
This method sets the ball color. |
void |
setColors(java.awt.Color pc,
java.awt.Color bc)
This method sets the colors. |
void |
setPath()
This method sets the path of the ball through the Galton board randomly, according to the probability. |
void |
setPath(int[] p)
This method sets the path of the ball through the Galton board. |
void |
setPathDrawn(boolean b)
This method sets the state of the path drawn boolean variable. |
void |
setPegColor(java.awt.Color c)
This method sets the peg color. |
void |
setProbability(double p)
This method sets the probability of a step to the right. |
void |
setRadius(double r)
This method sets the radius of the pegs and the ball. |
void |
setRows(int n)
This method sets the number of rows in the Galton board. |
Methods inherited from class edu.uah.math.devices.Graph |
---|
drawAxis, drawAxis, drawAxis, drawBox, drawBox, drawBoxPlot, drawBoxPlot, drawCircle, drawLabel, drawLine, drawPoint, drawTick, drawTick, fillBox, fillBox, fillBoxPlot, fillBoxPlot, fillCircle, format, getBottomMargin, getLeftMargin, getPointSize, getRightMargin, getTopMargin, getXGraph, getXMax, getXMin, getXPixels, getXScale, getYGraph, getYMax, getYMin, getYPixels, getYScale, setMargins, setPointSize, setScale, setShowModelDistribution |
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, 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 |
---|
public GaltonBoard(int n, double p, java.awt.Color pc, java.awt.Color bc)
n
- the number of the last ballRowp
- the probabiltiy of a step to the rightpc
- the peg colorbc
- the ball colorpublic GaltonBoard(int n, double p)
n
- the number of rows.p
- the probability of a step to the rightpublic GaltonBoard(int n)
n
- the number of rowspublic GaltonBoard()
Method Detail |
---|
public void setRows(int n)
n
- the number of rowspublic int getRows()
public void setProbability(double p)
p
- the probabilitypublic double getProbability()
public void setRadius(double r)
r
- the radiuspublic double getRadius()
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
g
- the graphics contextpublic void setPath(int[] p)
p
- the array of 0's (left moves) and 1's (right moves)public void setPath()
public void moveBall(int i)
i
- 1 for a move right, 0 for a move leftpublic int moveBall()
public int getBallColumn()
public int getBallRow()
public void drawBall(int x, int y)
x
- the x-coordinate of the pegy
- the y-coordinate of the pegpublic java.lang.String getBitString()
public java.lang.String getSubset()
public void reset()
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
e
- the mouse eventpublic void setColors(java.awt.Color pc, java.awt.Color bc)
pc
- the peg colorbc
- the ball colorpublic void setPegColor(java.awt.Color c)
c
- the peg colorpublic java.awt.Color getPegColor()
public void setBallColor(java.awt.Color c)
c
- the ball colorpublic java.awt.Color getBallColor()
public void setPathDrawn(boolean b)
b
- true if the path of the ball is drawnpublic boolean isPathDrawn()
public void mouseEntered(java.awt.event.MouseEvent event)
public void mouseExited(java.awt.event.MouseEvent event)
public void mousePressed(java.awt.event.MouseEvent event)
public void mouseReleased(java.awt.event.MouseEvent event)
public void mouseDragged(java.awt.event.MouseEvent event)
mouseDragged
in interface java.awt.event.MouseMotionListener
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |