edu.uah.math.devices
Class Urn

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.Urn
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible
Direct Known Subclasses:
UrnChain

public class Urn
extends javax.swing.JPanel

This class is a container (actually a panel) that holds balls. It is useful in sampling experiments in which balls are used as metaphors for objects in the population. The balls can be shown or hidden, and a sample of balls can be selected.

Version:
August, 2003
Author:
Dawn Duehring, Kyle Siegrist
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
static int WITH_REPLACEMENT
           
static int WITHOUT_REPLACEMENT
           
 
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
Urn()
          This default constructor creates a new urn with 10 balls of default size and color.
Urn(int n)
          This special constructor creates a new urn with a specified number of balls and with the default size 40 and color red.
Urn(int n, int s)
          This special constructor creates a new urn with a specified number of balls of a specified preferred size, and with the default ball color red and text color white
Urn(int n, int s, java.awt.Color bc, java.awt.Color tc)
          This general constructor creates a new urn with a specified number of balls of a specified preferred size and a specified ball color and text color The balls are added to the panel using a flow layout.
 
Method Summary
 Ball getBall(int i)
          This method returns a specified ball.
 int getBallCount()
          This method returns the number of balls.
 int[] getValues()
          This method returns the array of ball values.
 int getValues(int i)
          This method returns the value of an individual ball.
 boolean isDrawn()
          This method returns the common state of all of the balls.
 void sample(int N, int t)
          This method treats the balls as a sample from a population of a specified size.
 void setBallColor(java.awt.Color c)
          This method sets the ballcolor of all of the balls.
 void setBallCount(int n)
          This method sets the number of balls.
 void setDrawn(boolean b)
          This method sets the common state of all of the balls.
 void setTextColor(java.awt.Color c)
          This method sets the text color of all of the balls.
 void setValues(int[] v)
          This method sets the array of ball values.
 void setValues(int i, int x)
          This method sets the value of an individual ball.
 
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
 

Field Detail

WITHOUT_REPLACEMENT

public static final int WITHOUT_REPLACEMENT
See Also:
Constant Field Values

WITH_REPLACEMENT

public static final int WITH_REPLACEMENT
See Also:
Constant Field Values
Constructor Detail

Urn

public Urn(int n,
           int s,
           java.awt.Color bc,
           java.awt.Color tc)
This general constructor creates a new urn with a specified number of balls of a specified preferred size and a specified ball color and text color The balls are added to the panel using a flow layout.

Parameters:
n - the number of balls
s - the preferred size of the balls
bc - the ball color
tc - the text color

Urn

public Urn(int n,
           int s)
This special constructor creates a new urn with a specified number of balls of a specified preferred size, and with the default ball color red and text color white

Parameters:
n - the number of balls
s - the preferred size of the balls

Urn

public Urn(int n)
This special constructor creates a new urn with a specified number of balls and with the default size 40 and color red.

Parameters:
n - the number of balls

Urn

public Urn()
This default constructor creates a new urn with 10 balls of default size and color.

Method Detail

getBall

public Ball getBall(int i)
This method returns a specified ball.

Parameters:
i - the index
Returns:
the ball corresponding to the index

setBallCount

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

Parameters:
n - the number of balls in the urn

getBallCount

public int getBallCount()
This method returns the number of balls.

Returns:
the number of balls in the urn

setBallColor

public void setBallColor(java.awt.Color c)
This method sets the ballcolor of all of the balls.

Parameters:
c - the new color

setTextColor

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

Parameters:
c - the new color

setDrawn

public void setDrawn(boolean b)
This method sets the common state of all of the balls. If drawn, the balls are shown with their colors and values. If not drawn, the balls are shown without their values and in the background color.

Parameters:
b - true if drawn

isDrawn

public boolean isDrawn()
This method returns the common state of all of the balls. If drawn, the balls are shown with their colors and values. If not drawn, the balls are shown without their values and in the background color.

Returns:
true if drawn

setValues

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

Parameters:
v - the array of ball values

getValues

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

Returns:
the array of ball values

setValues

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

Parameters:
i - the index
x - the value

getValues

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

Parameters:
i - the index
Returns:
the value of the ball with the specified index

sample

public void sample(int N,
                   int t)
This method treats the balls as a sample from a population of a specified size. The type of sampling (without replacement or with replacement) is specified.

Parameters:
N - the popultaion size
t - the type of sampling (WITH_REPLCEMENT or WITHOUT_REPLACEMENT)