edu.uah.math.experiments
Class Experiment

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by java.applet.Applet
                  extended by javax.swing.JApplet
                      extended by edu.uah.math.experiments.Experiment
All Implemented Interfaces:
IExperiment, Pluginable, java.awt.event.ActionListener, java.awt.event.ItemListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.WindowListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.ChangeListener, javax.swing.RootPaneContainer
Direct Known Subclasses:
BallotExperiment, BertrandExperiment, BetaCoinExperiment, BinomialCoinExperiment, BinomialTimelineExperiment, BirthdayExperiment, BivariateNormalExperiment, BivariateUniformExperiment, BuffonCoinExperiment, BuffonNeedleExperiment, CardExperiment, ChiSquareFitExperiment, ChuckALuckExperiment, CoinDieExperiment, CoinSampleExperiment, CoinTossLawOfLargeNumbersExperiment, CouponCollectorExperiment, CrapsExperiment, DiceExperiment, DiceSampleExperiment, DieCoinExperiment, EstimateExperiment, ExponentialTimesCarExperiment, FiniteOrderStatisticExperiment, FireExperiment, GaltonBoardExperiment, GammaExperiment, LLN_SimpleExperiment, MarkovChainExperiment, MatchExperiment, MeanEstimateExperiment, MeanTestExperiment, MontyHallExperiment, NegativeBinomialExperiment, OrderStatisticExperiment, PointExperiment, Poisson2DExperiment, PoissonExperiment, PoissonSplitExperiment, PokerDiceExperiment, PokerExperiment, ProbabilityPlotExperiment, ProportionEstimateExperiment, ProportionTestExperiment, RandomVariableExperiment, RandomWalkExperiment, RedBlackExperiment, RouletteExperiment, SampleMeanExperiment, SamplingDistributionExperiment, SignTestExperiment, SimulationResampleExperiment, SpinnerExperiment, TriangleExperiment, UrnExperiment, VarianceEstimateExperiment, VarianceTestExperiment, VoterExperiment

public class Experiment
extends javax.swing.JApplet
implements java.awt.event.ActionListener, java.awt.event.ItemListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.event.WindowListener, javax.swing.event.ChangeListener, java.io.Serializable, IExperiment

This class defines a basic, discrete time stochastic process that can be subclassed.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JApplet
javax.swing.JApplet.AccessibleJApplet
 
Nested classes/interfaces inherited from class java.applet.Applet
java.applet.Applet.AccessibleApplet
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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
protected  javax.swing.JApplet applet
           
protected  javax.swing.JPanel componentPanel
           
static java.awt.Color GREEN
           
static java.awt.Color RED
           
protected  boolean showModelDistribution
           
 javax.swing.JComboBox stopChoice
           
 int stopCount
           
 int stopFreq
           
 boolean stopNow
           
 int time
           
 javax.swing.Timer timer
           
protected  javax.swing.JPanel toolBars
           
 int toolIndex
           
 int updateCount
           
 int updateFreq
           
 
Fields inherited from class javax.swing.JApplet
accessibleContext, rootPane, rootPaneCheckingEnabled
 
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
Experiment()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          This method handles the action events associated with the simulation buttons.
 void addComponent(java.awt.Component c, int x, int y, int w, int h)
          This method adds a component to the component panel at a specified row and column, with a specified row span and column span, and with default horizontal and vertical weights.
 void addComponent(java.awt.Component c, int x, int y, int w, int h, int f)
          This method adds a component to the component panel at a specified row and column, with a specified row span and column span, and specified fill parameter.
 void addComponent(java.awt.Component c, int x, int y, int w, int h, int wx, int wy)
          This method adds a component to the component panel at a specified row and column, specified row span and column span, and specified horizontal and vertical weights.
 void addTool(java.awt.Component c)
          This method adds a tool to the main toolbar, in the next to the last position (just before the About button).
 void addToolBar(java.awt.Component c)
          This method adds a new component to the toolbar panel.
 void clearToolBars()
           
 void doExperiment()
          This method defines what the experiment actually does, and should be overridden, when this class is subclassed, to define an actual random pocess.
 java.lang.String format(double x)
          This method formats a number as a string in a specified way.
 java.lang.String getAppletInfo()
          This method returns basic copyright, author, and other metadata information.
 javax.swing.JPanel getComponentPanel()
          This method gets the component panel.
 java.awt.Container getDisplayPane()
           
 javax.swing.JToolBar getMainToolBar()
          This method returns the main toolbar.
 java.lang.String getOnlineDescription()
           
 javax.swing.JTable getResultTable()
           
 javax.swing.JComboBox getStopChoice()
          This method returns the stop choice.
 int getStopFreq()
          This method returns the stop frequency.
 int getTime()
          This method gets the time parameter of the stochastic process.
 javax.swing.Timer getTimer()
          This method returns the timer.
 javax.swing.JComboBox getUpdateChoice()
          This method returns the update choice.
 void graphUpdate()
           
 void init()
          This method initializes the experiment, by setting up the basic simulation buttons (step, run, stop, reset), and the update and stop choices on the main toolbar.
 void initialize()
           
 void itemStateChanged(java.awt.event.ItemEvent e)
          This method handles the choice events, associated with the update and stop choices.
 void mouseClicked(java.awt.event.MouseEvent event)
          Mouse events
 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 event)
          Mouse motion events
 void mousePressed(java.awt.event.MouseEvent event)
           
 void mouseReleased(java.awt.event.MouseEvent event)
           
 void pasteData(java.awt.datatransfer.Clipboard c)
           
 void playnote(boolean b)
          This method plays note 1 if the boolean argument is true and note 0 otherwise.
 void playnote(int i)
          This method plays one of the standard "telephone" notes 0.au through 9.au.
 void reset()
          This method is the default reset method, that resets the process to its initial state.
 void run()
          This method runs the experiment is repeatedly, and the update and stop counters incremented on each run.
 void setApplet(javax.swing.JApplet applet)
           
 void setDecimalFormat(java.text.DecimalFormat d)
          This methd sets the decimal format, so that the properties of the decimal format can then be changed.
 void setShowModelDistribution(boolean flag)
           
protected  void setStopChoice(int index)
          This method sets the stop-choice.
 void setStopChoiceTipText(java.lang.String str)
          This method sets the stop-choice.
 void setStopFreq(int i)
          This method sets the stop frequency.
 void setStopNow(boolean b)
          This method defines the boolean variable that stops the process, when the simulation is in run mode.
 void stateChanged(javax.swing.event.ChangeEvent e)
          JSlider events
 void step()
          This method is the default step method, that runs the process one time unit.
 void stop()
          This method stops the simulation when the simulation is in run mode..
 void update()
          This method is the default update method and defines how the display is updated.
 void windowActivated(java.awt.event.WindowEvent event)
           
 void windowClosed(java.awt.event.WindowEvent event)
           
 void windowClosing(java.awt.event.WindowEvent event)
           
 void windowDeactivated(java.awt.event.WindowEvent event)
           
 void windowDeiconified(java.awt.event.WindowEvent event)
           
 void windowIconified(java.awt.event.WindowEvent event)
           
 void windowOpened(java.awt.event.WindowEvent event)
          Window events
 
Methods inherited from class javax.swing.JApplet
addImpl, createRootPane, getAccessibleContext, getContentPane, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isRootPaneCheckingEnabled, paramString, remove, repaint, setContentPane, setGlassPane, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.applet.Applet
destroy, getAppletContext, getAudioClip, getAudioClip, getCodeBase, getDocumentBase, getImage, getImage, getLocale, getParameter, getParameterInfo, isActive, newAudioClip, play, play, resize, resize, setStub, showStatus, start
 
Methods inherited from class java.awt.Panel
addNotify
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.ucla.stat.SOCR.core.Pluginable
getName
 

Field Detail

time

public int time

updateCount

public int updateCount

stopCount

public int stopCount

updateFreq

public int updateFreq

stopFreq

public int stopFreq

toolIndex

public int toolIndex

stopNow

public boolean stopNow

toolBars

protected javax.swing.JPanel toolBars

componentPanel

protected javax.swing.JPanel componentPanel

stopChoice

public javax.swing.JComboBox stopChoice

timer

public javax.swing.Timer timer

RED

public static final java.awt.Color RED

GREEN

public static final java.awt.Color GREEN

applet

protected javax.swing.JApplet applet

showModelDistribution

protected boolean showModelDistribution
Constructor Detail

Experiment

public Experiment()
Method Detail

init

public void init()
This method initializes the experiment, by setting up the basic simulation buttons (step, run, stop, reset), and the update and stop choices on the main toolbar. The record table that records the results of the experiment is initialized.

Overrides:
init in class java.applet.Applet

getTime

public int getTime()
This method gets the time parameter of the stochastic process. If the process is to replicate a basic random experiment, then the time parameter is the number of runs.

Specified by:
getTime in interface IExperiment
Returns:
the current time parameter of the random process

pasteData

public void pasteData(java.awt.datatransfer.Clipboard c)
Specified by:
pasteData in interface IExperiment

getAppletInfo

public java.lang.String getAppletInfo()
This method returns basic copyright, author, and other metadata information.

Specified by:
getAppletInfo in interface IExperiment
Overrides:
getAppletInfo in class java.applet.Applet
Returns:
applet information

getOnlineDescription

public java.lang.String getOnlineDescription()
Specified by:
getOnlineDescription in interface IExperiment

stop

public void stop()
This method stops the simulation when the simulation is in run mode..

Specified by:
stop in interface IExperiment
Overrides:
stop in class java.applet.Applet

run

public void run()
This method runs the experiment is repeatedly, and the update and stop counters incremented on each run. If the update count equals the update frequency, the update method is called. If the stop count equals the stop frequency, the simulation is stopped.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
This method handles the action events associated with the simulation buttons. The single step button calls the step method, which runs the experiment one time, and then stops. The run button calls the run method, which runs the experiment repeatedly. The stop button calls the stop method, which stops the run mode and then calls the update method if necessary. The reset button callse the reset method. The about button shows a message dialog box with the text from getAppletInfo method. This method also handles the timer events.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - the action event

itemStateChanged

public void itemStateChanged(java.awt.event.ItemEvent e)
This method handles the choice events, associated with the update and stop choices.

Specified by:
itemStateChanged in interface java.awt.event.ItemListener
Parameters:
e - the item event

doExperiment

public void doExperiment()
This method defines what the experiment actually does, and should be overridden, when this class is subclassed, to define an actual random pocess.

Specified by:
doExperiment in interface IExperiment

step

public void step()
This method is the default step method, that runs the process one time unit. This method can be overridden to add sound, additional annimation, or other elements.

Specified by:
step in interface IExperiment

reset

public void reset()
This method is the default reset method, that resets the process to its initial state. This method should be overridden.

Specified by:
reset in interface IExperiment

update

public void update()
This method is the default update method and defines how the display is updated. This method should be overridden.

Specified by:
update in interface IExperiment

graphUpdate

public void graphUpdate()
Specified by:
graphUpdate in interface IExperiment

setStopNow

public void setStopNow(boolean b)
This method defines the boolean variable that stops the process, when the simulation is in run mode.

Specified by:
setStopNow in interface IExperiment
Parameters:
b - the boolean variable that defines when the experiment stops

getStopFreq

public int getStopFreq()
This method returns the stop frequency.

Specified by:
getStopFreq in interface IExperiment
Returns:
the number of runs until the simulation stops.

setStopFreq

public void setStopFreq(int i)
This method sets the stop frequency.

Specified by:
setStopFreq in interface IExperiment
Parameters:
i - the number of runs until the simulation stops

format

public java.lang.String format(double x)
This method formats a number as a string in a specified way.

Parameters:
x - the number to be formatted.
Returns:
the number formatted as a string

setDecimalFormat

public void setDecimalFormat(java.text.DecimalFormat d)
This methd sets the decimal format, so that the properties of the decimal format can then be changed.


addComponent

public void addComponent(java.awt.Component c,
                         int x,
                         int y,
                         int w,
                         int h,
                         int wx,
                         int wy)
This method adds a component to the component panel at a specified row and column, specified row span and column span, and specified horizontal and vertical weights.

Parameters:
c - the component
x - the column number of the component
y - the row number of the component
w - the number of columns spanned by the component
h - the number of rows panned by the component
wx - the horizontal weight factor;
wy - the vertical weight factor;

addComponent

public void addComponent(java.awt.Component c,
                         int x,
                         int y,
                         int w,
                         int h,
                         int f)
This method adds a component to the component panel at a specified row and column, with a specified row span and column span, and specified fill parameter.

Parameters:
c - the component
x - the column number of the component
y - the row number of the component
w - the number of columns spanned by the component
h - the number of rows panned by the component
f - the fill parameter;

addComponent

public void addComponent(java.awt.Component c,
                         int x,
                         int y,
                         int w,
                         int h)
This method adds a component to the component panel at a specified row and column, with a specified row span and column span, and with default horizontal and vertical weights.

Parameters:
c - the component
x - the column number of the component
y - the row number of the component
w - the row span of the component
h - the column span of the component

addToolBar

public void addToolBar(java.awt.Component c)
This method adds a new component to the toolbar panel.

Parameters:
c - the component to be added

clearToolBars

public void clearToolBars()

addTool

public void addTool(java.awt.Component c)
This method adds a tool to the main toolbar, in the next to the last position (just before the About button).

Parameters:
c - the component to be added to the toolbar

getMainToolBar

public javax.swing.JToolBar getMainToolBar()
This method returns the main toolbar.

Returns:
the main toolbar

getComponentPanel

public javax.swing.JPanel getComponentPanel()
This method gets the component panel.

Returns:
the component panel

getUpdateChoice

public javax.swing.JComboBox getUpdateChoice()
This method returns the update choice.

Returns:
the update choice

getStopChoice

public javax.swing.JComboBox getStopChoice()
This method returns the stop choice.

Returns:
the stop choice

setStopChoice

protected void setStopChoice(int index)
This method sets the stop-choice.

Parameters:
index - is the index to choose from the stopChoice List

setStopChoiceTipText

public void setStopChoiceTipText(java.lang.String str)
This method sets the stop-choice.

Parameters:
index - is the index to choose from the stopChoice List

getTimer

public javax.swing.Timer getTimer()
This method returns the timer.

Returns:
the simulation timer

playnote

public void playnote(int i)
This method plays one of the standard "telephone" notes 0.au through 9.au. If the index is out of range, the note corresponding to the remainder mod 10 is played.

Parameters:
i - the note index

playnote

public void playnote(boolean b)
This method plays note 1 if the boolean argument is true and note 0 otherwise.

Parameters:
b - the boolean variable

stateChanged

public void stateChanged(javax.swing.event.ChangeEvent e)
JSlider events

Specified by:
stateChanged in interface javax.swing.event.ChangeListener

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Mouse events

Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)
Mouse motion events

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

windowOpened

public void windowOpened(java.awt.event.WindowEvent event)
Window events

Specified by:
windowOpened in interface java.awt.event.WindowListener

windowClosing

public void windowClosing(java.awt.event.WindowEvent event)
Specified by:
windowClosing in interface java.awt.event.WindowListener

windowClosed

public void windowClosed(java.awt.event.WindowEvent event)
Specified by:
windowClosed in interface java.awt.event.WindowListener

windowIconified

public void windowIconified(java.awt.event.WindowEvent event)
Specified by:
windowIconified in interface java.awt.event.WindowListener

windowDeiconified

public void windowDeiconified(java.awt.event.WindowEvent event)
Specified by:
windowDeiconified in interface java.awt.event.WindowListener

windowActivated

public void windowActivated(java.awt.event.WindowEvent event)
Specified by:
windowActivated in interface java.awt.event.WindowListener

windowDeactivated

public void windowDeactivated(java.awt.event.WindowEvent event)
Specified by:
windowDeactivated in interface java.awt.event.WindowListener

setApplet

public void setApplet(javax.swing.JApplet applet)
Specified by:
setApplet in interface Pluginable

getDisplayPane

public java.awt.Container getDisplayPane()
Specified by:
getDisplayPane in interface Pluginable

initialize

public void initialize()
Specified by:
initialize in interface IExperiment

setShowModelDistribution

public void setShowModelDistribution(boolean flag)
Specified by:
setShowModelDistribution in interface IExperiment

getResultTable

public javax.swing.JTable getResultTable()
Specified by:
getResultTable in interface IExperiment