Class JAnalogClock

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Runnable, Accessible

public class JAnalogClock extends JPanel implements Runnable
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:
  • Constructor Details

    • JAnalogClock

      public JAnalogClock()
      Default constructor to set the time to whenever the class is instantiated
    • JAnalogClock

      public JAnalogClock(Date InDate)
      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 to
      minute - the minute to set the clock to
      second - 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

      public void setBackgroundColor(Color c)
      Change the background color of the clock. Default color is Color.lightGray
      Parameters:
      c - the new background color
    • getBackgroundColor

      public Color getBackgroundColor()
      Retrieves the background color
      Returns:
      the background color.
    • setHourHandColor

      public void setHourHandColor(Color c)
      Change the hour hand color of the clock. Default color is blue.
      Parameters:
      c - the new hour hand color
    • getHourHandColor

      public Color getHourHandColor()
      Retrieves the hour hand color
      Returns:
      the hour hand color.
    • setMinuteHandColor

      public void setMinuteHandColor(Color c)
      Change the minute hand color of the clock. Default color is blue.
      Parameters:
      c - the new minute hand color
    • getMinuteHandColor

      public Color getMinuteHandColor()
      Retrieves the minute hand color
      Returns:
      the minute hand color.
    • setSecondHandColor

      public void setSecondHandColor(Color c)
      Change the second hand color of the clock. Default color is black.
      Parameters:
      c - the new second hand color
    • getSecondHandColor

      public Color getSecondHandColor()
      Retrieves the second hand color
      Returns:
      the second hand color.
    • setHoursDotColor

      public void setHoursDotColor(Color c)
      Change the hours dot color of the clock. Default color is red.
      Parameters:
      c - the new hours dot color
    • getHoursDotColor

      public Color getHoursDotColor()
      Retrieves the hours dot color
      Returns:
      the hours dot color.
    • setMinutesDotColor

      public void setMinutesDotColor(Color c)
      Change the Minutes dot color of the clock. Default color is white.
      Parameters:
      c - the new Minutes dot color
    • getMinutesDotColor

      public 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 via start() 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. When stop() 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 via start() 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. When stop() 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 via start() 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. When stop() 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 class Component
      Returns:
      whether the clock is traversable with the TAB key. Always false.
    • setTime

      public void setTime(Date InTime)
      Set the display time for the clock when it's not running.
      Parameters:
      InTime - A date object representing the current time to display.
    • getTime

      public Date 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 by start to create the thread. Do Not call this method directly.
      Specified by:
      run in interface Runnable
    • 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

      public void update(Graphics g)
      Draws the clock onto the double buffer, and displays it.
      Overrides:
      update in class JComponent
      Parameters:
      g - The graphics device to draw on
    • paint

      public void paint(Graphics g)
      Called by the system to repaint the clock when needed.
      Overrides:
      paint in class JComponent
      Parameters:
      g - The graphics device to draw on