Package com.portal.pfc.ui.datetime
Class JAnalogClock
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
com.portal.pfc.ui.datetime.JAnalogClock
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Runnable,Accessible
Displays an analog clock corresponding to the time set on it.
It can be run in two modes - just display a certain time or
as a running clock that can be offset by any amount of time.
- Author:
- Nathan Brizzee
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
Fields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor to set the time to whenever the class is instantiatedJAnalogClock(int hour, int minute, int second) Constructor to set the clock to a certain timeJAnalogClock(Date InDate) Constructor to set the clock to a certain time -
Method Summary
Modifier and TypeMethodDescriptionRetrieves the background colorintgetHour()Retrieves the current hour the clock is running at or is displaying.Retrieves the hour hand colorintRetrieves the Hour offset valueRetrieves the hours dot colorRetrieves the minute hand colorintRetrieves the current minute the clock is running at.Retrieves the Minutes dot colorintRetrieves the Minute offset valueintRetrieves the refresh intervalRetrieves the second hand colorintRetrieves the current second the clock is running at.intRetrieves the Seconds offset valuegetTime()Gets the Date/Time of the clockbooleanReturns whether the auto update tooltip value is set to true or not.booleanReturns whether the clock can be traversed with the TAB key.booleanreturns true if the clock is in run mode [start() called] or false if the clock is not running [stop() called].voidCalled by the system to repaint the clock when needed.voidrun()Method that is called bystartto create the thread.voidsetAutoUpdateToolTipText(boolean autoUpdateToolTipText) Sepcifies whether the control should update the tooltip as the clock runs.voidChange the background color of the clock.voidsetHour(int value) Sets the hour to be shown on the clock.voidChange the hour hand color of the clock.voidsetHourOffset(int value) Changes the number of hours to offset the clock by.voidChange the hours dot color of the clock.voidChange the minute hand color of the clock.voidsetMinutes(int value) Sets the minutes to be shown on the clock.voidChange the Minutes dot color of the clock.voidsetMinutesOffset(int value) Changes the number of minutes to offset the clock by.voidsetRefreshInterval(int interval) Change the refresh interval.voidChange the second hand color of the clock.voidsetSeconds(int value) Sets the seconds to be shown on the clock.voidsetSecondsOffset(int value) Changes the number of Seconds to offset the clock by.voidSet the display time for the clock when it's not running.voidstart()Creates and starts a thread that runs the clockvoidstop()Kills the thread that runs the clockvoidDraws the clock onto the double buffer, and displays it.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, unregisterKeyboardActionMethods 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, transferFocusDownCycle, validate, validateTreeMethods 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Constructor Details
-
JAnalogClock
public JAnalogClock()Default constructor to set the time to whenever the class is instantiated -
JAnalogClock
Constructor to set the clock to a certain time- Parameters:
InDate- the date class representing the time to set the clock to.
-
JAnalogClock
public JAnalogClock(int hour, int minute, int second) Constructor to set the clock to a certain time- Parameters:
hour- the hour to set the clock tominute- the minute to set the clock tosecond- the second to set the clock to
-
-
Method Details
-
setRefreshInterval
public void setRefreshInterval(int interval) Change the refresh interval. Default is 100. Must be greater than 0.- Parameters:
interval- the new refresh interval
-
getRefreshInterval
public int getRefreshInterval()Retrieves the refresh interval- Returns:
- the refresh interval
-
setAutoUpdateToolTipText
public void setAutoUpdateToolTipText(boolean autoUpdateToolTipText) Sepcifies whether the control should update the tooltip as the clock runs. Default is true- Parameters:
value- true = update the tooltip to match the current clock time.
-
isAutoUpdateToolTipText
public boolean isAutoUpdateToolTipText()Returns whether the auto update tooltip value is set to true or not.- Returns:
- whether the tooltip is set to autoupdate or not.
-
setBackgroundColor
Change the background color of the clock. Default color is Color.lightGray- Parameters:
c- the new background color
-
getBackgroundColor
Retrieves the background color- Returns:
- the background color.
-
setHourHandColor
Change the hour hand color of the clock. Default color is blue.- Parameters:
c- the new hour hand color
-
getHourHandColor
Retrieves the hour hand color- Returns:
- the hour hand color.
-
setMinuteHandColor
Change the minute hand color of the clock. Default color is blue.- Parameters:
c- the new minute hand color
-
getMinuteHandColor
Retrieves the minute hand color- Returns:
- the minute hand color.
-
setSecondHandColor
Change the second hand color of the clock. Default color is black.- Parameters:
c- the new second hand color
-
getSecondHandColor
Retrieves the second hand color- Returns:
- the second hand color.
-
setHoursDotColor
Change the hours dot color of the clock. Default color is red.- Parameters:
c- the new hours dot color
-
getHoursDotColor
Retrieves the hours dot color- Returns:
- the hours dot color.
-
setMinutesDotColor
Change the Minutes dot color of the clock. Default color is white.- Parameters:
c- the new Minutes dot color
-
getMinutesDotColor
Retrieves the Minutes dot color- Returns:
- the Minutes dot color.
-
setHourOffset
public void setHourOffset(int value) Changes the number of hours to offset the clock by. Default is 0- Parameters:
value- the number of hours to offset the clock by. Valid values are +24 to -24.
-
getHourOffset
public int getHourOffset()Retrieves the Hour offset value- Returns:
- the Hour offset value
-
setMinutesOffset
public void setMinutesOffset(int value) Changes the number of minutes to offset the clock by. Default is 0- Parameters:
value- the number of minutes to offset the clock by. Valid values are +60 to -60.
-
getMinutesOffset
public int getMinutesOffset()Retrieves the Minute offset value- Returns:
- the Minute offset value
-
setSecondsOffset
public void setSecondsOffset(int value) Changes the number of Seconds to offset the clock by. Default is 0- Parameters:
value- the number of Seconds to offset the clock by. Valid values are +60 to -60.
-
getSecondsOffset
public int getSecondsOffset()Retrieves the Seconds offset value- Returns:
- the Seconds offset value
-
setHour
public void setHour(int value) Sets the hour to be shown on the clock. When the clock starts running viastart()it will display the actual time from the computer +/- the offsets, not the values the clock was set to in the constructor or the setHour, setMinutes, or setSeconds functions. Whenstop()is called, the clock will display whatever the time was when it was stopped. Default is from constructor.- Parameters:
value- the number to set the display hour to. Valid values are 0 to 23.
-
getHour
public int getHour()Retrieves the current hour the clock is running at or is displaying.- Returns:
- the current hour
-
setMinutes
public void setMinutes(int value) Sets the minutes to be shown on the clock. When the clock starts running viastart()it will display the actual time from the computer +/- the offsets, not the values the clock was set to in the constructor or the setHour, setMinutes, or setSeconds functions. Whenstop()is called, the clock will display whatever the time was when it was stopped. Default is from constructor.- Parameters:
value- the number to set the display minutes to. Valid values are 0 to 59.
-
getMinutes
public int getMinutes()Retrieves the current minute the clock is running at.- Returns:
- the current minute
-
setSeconds
public void setSeconds(int value) Sets the seconds to be shown on the clock. When the clock starts running viastart()it will display the actual time from the computer +/- the offsets, not the values the clock was set to in the constructor or the setHour, setMinutes, or setSeconds functions. Whenstop()is called, the clock will display whatever the time was when it was stopped. Default is from constructor.- Parameters:
value- the number to set the display seconds to. Valid values are 0 to 59.
-
getSeconds
public int getSeconds()Retrieves the current second the clock is running at.- Returns:
- the current second
-
isFocusTraversable
public boolean isFocusTraversable()Returns whether the clock can be traversed with the TAB key. Always false.- Overrides:
isFocusTraversablein classComponent- Returns:
- whether the clock is traversable with the TAB key. Always false.
-
setTime
Set the display time for the clock when it's not running.- Parameters:
InTime- A date object representing the current time to display.
-
getTime
Gets the Date/Time of the clock- Returns:
- The clock's Date/Time
-
start
public void start()Creates and starts a thread that runs the clock -
stop
public void stop()Kills the thread that runs the clock -
run
public void run()Method that is called bystartto create the thread. Do Not call this method directly. -
isRunning
public boolean isRunning()returns true if the clock is in run mode [start() called] or false if the clock is not running [stop() called]. -
update
Draws the clock onto the double buffer, and displays it.- Overrides:
updatein classJComponent- Parameters:
g- The graphics device to draw on
-
paint
Called by the system to repaint the clock when needed.- Overrides:
paintin classJComponent- Parameters:
g- The graphics device to draw on
-