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.AccessibleJPanel
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
Nested 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_WINDOW
Fields inherited from class java.awt.Component
accessibleContext, 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
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 colorint
getHour()
Retrieves the current hour the clock is running at or is displaying.Retrieves the hour hand colorint
Retrieves the Hour offset valueRetrieves the hours dot colorRetrieves the minute hand colorint
Retrieves the current minute the clock is running at.Retrieves the Minutes dot colorint
Retrieves the Minute offset valueint
Retrieves the refresh intervalRetrieves the second hand colorint
Retrieves the current second the clock is running at.int
Retrieves the Seconds offset valuegetTime()
Gets the Date/Time of the clockboolean
Returns whether the auto update tooltip value is set to true or not.boolean
Returns whether the clock can be traversed with the TAB key.boolean
returns true if the clock is in run mode [start() called] or false if the clock is not running [stop() called].void
Called by the system to repaint the clock when needed.void
run()
Method that is called bystart
to create the thread.void
setAutoUpdateToolTipText
(boolean autoUpdateToolTipText) Sepcifies whether the control should update the tooltip as the clock runs.void
Change the background color of the clock.void
setHour
(int value) Sets the hour to be shown on the clock.void
Change the hour hand color of the clock.void
setHourOffset
(int value) Changes the number of hours to offset the clock by.void
Change the hours dot color of the clock.void
Change the minute hand color of the clock.void
setMinutes
(int value) Sets the minutes to be shown on the clock.void
Change the Minutes dot color of the clock.void
setMinutesOffset
(int value) Changes the number of minutes to offset the clock by.void
setRefreshInterval
(int interval) Change the refresh interval.void
Change the second hand color of the clock.void
setSeconds
(int value) Sets the seconds to be shown on the clock.void
setSecondsOffset
(int value) Changes the number of Seconds to offset the clock by.void
Set the display time for the clock when it's not running.void
start()
Creates and starts a thread that runs the clockvoid
stop()
Kills the thread that runs the clockvoid
Draws the clock onto the double buffer, and displays it.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, 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, unregisterKeyboardAction
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, 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, 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:
isFocusTraversable
in 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 bystart
to 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:
update
in classJComponent
- Parameters:
g
- The graphics device to draw on
-
paint
Called by the system to repaint the clock when needed.- Overrides:
paint
in classJComponent
- Parameters:
g
- The graphics device to draw on
-