public class Spinner
extends javax.swing.JComponent
implements java.awt.event.MouseMotionListener, java.io.Serializable
javax.swing.JComponent.AccessibleJComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Constructor and Description |
---|
Spinner()
This default constructor creates a new spinner with four equal divisions.
|
Spinner(double[] p)
This special constructor creates a new spinner with a specified array of
probabilities and a the default array of colors.
|
Spinner(double[] p,
java.awt.Color[] c)
This general constructor creates a new spinner with a specified array of
probabilities and a specified array of colors.
|
Spinner(int n)
This special constuctor creates a new spinner with a specified number of
equal sized divisions and the default array of colors.
|
Spinner(int n,
java.awt.Color[] c)
This special constuctor creates a new spinner with a specified number of
equal sized divisions and a specified array of colors.
|
Modifier and Type | Method and Description |
---|---|
double |
getAngle()
This method returns the angle.
|
java.awt.Color[] |
getColors()
This method returns the array of colors
|
java.awt.Color |
getColors(int i)
This method returns an individual color
|
int |
getDivisions()
This method returns the number of divisions.
|
double[] |
getProbabilities()
This method returns the all of the probabilities.
|
double |
getProbabilities(int i)
This method returns an individual probability.
|
int |
getValue()
This method returns the current value of the spinner
|
int |
getValue(double a)
This method computes the value (sector number) corresponding
to a give angle.
|
void |
mouseDragged(java.awt.event.MouseEvent event) |
void |
mouseMoved(java.awt.event.MouseEvent e)
This method handles the mouse move event.
|
void |
paintComponent(java.awt.Graphics g)
This method paints the spinner based on the number of divisions and paints
the pointer based on the random angle computed in the spin method.
|
void |
setAngle(double a)
This method sets a specific angle measure and computes the value of the spin
corresponding to that angle.
|
void |
setColors(java.awt.Color[] c)
This method sets the array of colors.
|
void |
setColors(int i,
java.awt.Color c)
This method sets an individual color.
|
void |
setDefaultColors()
This method defines the default color array.
|
void |
setDivisions(int n)
This method sets the number of divisions.
|
void |
setProbabilities(double[] p)
This method sets the array of probabilities.
|
void |
setProbabilities(int i,
double p)
This method sets an individual probability.
|
void |
spin()
This method "spins" the spinner by computing a random angle and the value of
a spin based on that angle.
|
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, updateUI
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, transferFocusDownCycle, validate, validateTree
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, transferFocusBackward, transferFocusUpCycle
public Spinner(double[] p, java.awt.Color[] c)
p
- the array of probabilitiesc
- the array of colorspublic Spinner(double[] p)
p
- the array of probabilitiespublic Spinner(int n, java.awt.Color[] c)
n
- the number of divisionsc
- the array of colorspublic Spinner(int n)
n
- the number of divisionspublic Spinner()
public void setProbabilities(double[] p)
p
- the array of probabilitiespublic double[] getProbabilities()
public void setProbabilities(int i, double p)
i
- the indexp
- the probabilitypublic double getProbabilities(int i)
i
- the indexpublic void setColors(java.awt.Color[] c)
c
- the array of colors.public java.awt.Color[] getColors()
public void setColors(int i, java.awt.Color c)
i
- the indexc
- the color of the indexpublic java.awt.Color getColors(int i)
i
- the indexpublic void setDefaultColors()
public void setDivisions(int n)
n
- the number of divisionspublic int getDivisions()
public void setAngle(double a)
a
- the angle of the pointer relative to the horizontal raypublic double getAngle()
public void spin()
public int getValue(double a)
a
- the anglepublic int getValue()
public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
g
- the graphics contextpublic void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
e
- the mouse eventpublic void mouseDragged(java.awt.event.MouseEvent event)
mouseDragged
in interface java.awt.event.MouseMotionListener