|
||||||||||
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 edu.uah.math.devices.Voters
public class Voters
This class models a rectangular array of voters (a metaphor for a site that can be in one of several states. Each voter at each time can be in one of a finite set of states representd as colors. The voters are actually represented as colored squares.
Nested Class Summary |
---|
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 | |
---|---|
Voters()
This default constructor creates a new array of voters with 10 rows, 10 columns and the default uniform probability array, and default preferred voter size. |
|
Voters(int m,
int n)
This special constructor creates a new array of voters with a specified number of rows and columns, and default voter size, colors and probabilities. |
|
Voters(int m,
int n,
int s)
This special constructor creates a new array of voters with a specified number of rows and columns, a specified size, and default colors and probabilities.. |
|
Voters(int m,
int n,
int s,
java.awt.Color[] c)
This special constructor creates a new array of voters with a specified number of rows and columns, a specified array of colors (states), a specified size, a specified color array and default probabilities. |
|
Voters(int m,
int n,
int s,
java.awt.Color[] c,
double[] p)
This general constructor creates a new array of voters with a specified number of rows and columns, a specified array of colors (states), a specified probability array, and a preferred voter size. |
Method Summary | |
---|---|
void |
doExperiment()
This method performs the voter experiment. |
java.awt.Color[] |
getColors()
This method returns the array of colors (states). |
java.awt.Color |
getColors(int i)
This method returns a particular state (color). |
int |
getColumns()
This method returns the number of columns. |
int |
getEditState()
This method returns the edit state, the state that a voter will be changed to when a user clicks on the voter. |
java.awt.Point |
getNeighbor()
This emthod returns the currently selected neighbor. |
int |
getNewState()
This method returns the new state. |
double |
getProbabilites(int i)
This method returns an individual probability. |
double[] |
getProbabilities()
This method gets the array of probabilities. |
int |
getRows()
This method returns the number of rows. |
int |
getStateCount(int i)
This method returns the number of voters in a specified state. |
int[][] |
getStates()
This method returns the array of states. |
int |
getStates(int x,
int y)
This method returns the state of a specified voter. |
int |
getStatesAlive()
This method returns the number of states alive (that is, at least one voter has this state. |
java.awt.Point |
getVoter()
This method returns the currently selected voter. |
boolean |
isConsensus()
This method checks to see if the voters are all in the same state. |
boolean |
isNewDeath()
This method checks to see if a state has died. |
void |
mouseClicked(java.awt.event.MouseEvent e)
This method changes the state of the voter clicked on to the current edit state. |
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 tracks the voter under the mouse cursor. |
void |
mousePressed(java.awt.event.MouseEvent event)
|
void |
mouseReleased(java.awt.event.MouseEvent event)
|
void |
paintComponent(java.awt.Graphics g)
This method paints the voter canvas. |
void |
reset()
This method resets the voters. |
void |
setColors(java.awt.Color[] c)
This method sets the array of color (states). |
void |
setColumns(int m)
This method sets the number of columns. |
void |
setEditState(int s)
This method sets the edit state, the state that a voter will be changed to when a user clicks on the voter. |
void |
setParameters(int m,
int n)
This method sets the parameters: the number of rows and columns. |
void |
setParameters(int m,
int n,
int s)
This method sets the parameters: the number of rows and columns, and the array of states (colors). |
void |
setProbabilities(double[] p)
This method sets the probabilities for selecting a neighbor. |
void |
setProbabilities(int i,
double p)
This method sets and individual probability for selecting a neighbor. |
void |
setRows(int n)
This method sets the number of rows. |
void |
setStates(int[][] s)
This method sets the array of states. |
void |
setStates(int x,
int y,
int s)
This method changes the state of a specified voter to a specified new state. |
Methods inherited from class javax.swing.JComponent |
---|
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, 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, updateUI |
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 Voters(int m, int n, int s, java.awt.Color[] c, double[] p)
m
- the number of columnsn
- the number of rowss
- the size of a voterc
- the array of colors (states)p
- the array of probabilitiespublic Voters(int m, int n, int s, java.awt.Color[] c)
m
- the number of columnsn
- the number of rowss
- the size of a voterc
- the array of colors (states)public Voters(int m, int n, int s)
m
- the number of columnsn
- the number of rowss
- the size of a voterpublic Voters(int m, int n)
m
- the number of columnsn
- the number of rowspublic Voters()
Method Detail |
---|
public void setParameters(int m, int n, int s)
m
- the number of columnsn
- the number of rowss
- the voter sizepublic void setParameters(int m, int n)
m
- the number of columnsn
- the number of rowspublic void setColumns(int m)
m
- the number of columnspublic int getColumns()
public void setRows(int n)
n
- the number of rowspublic int getRows()
public void setColors(java.awt.Color[] c)
c
- the array of colorspublic java.awt.Color[] getColors()
public java.awt.Color getColors(int i)
i
- the index
public void setProbabilities(double[] p)
p
- the array of probabilitiespublic void setProbabilities(int i, double p)
public double[] getProbabilities()
public double getProbabilites(int i)
i
- the index
public void setEditState(int s)
s
- the new statepublic int getEditState()
public void setStates(int x, int y, int s)
x
- the x-coordinate of the votery
- the y-coordiante of the voters
- the new statepublic void setStates(int[][] s)
s
- the array of statespublic int getStates(int x, int y)
x
- the x-coordinate of the votery
- the y-coordinate of the voter
public int[][] getStates()
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
public void reset()
public int getStateCount(int i)
i
- the state
public void doExperiment()
public int getStatesAlive()
public boolean isNewDeath()
public boolean isConsensus()
public void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
e
- the mouse eventpublic java.awt.Point getVoter()
public int getNewState()
public java.awt.Point getNeighbor()
public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
e
- the mouse eventpublic void mouseEntered(java.awt.event.MouseEvent event)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent event)
mouseExited
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent event)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent event)
mouseReleased
in interface java.awt.event.MouseListener
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 |