Class JTimeChooser

All Implemented Interfaces:
ActionListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, ChangeListener, RootPaneContainer, WindowConstants

public final class JTimeChooser extends JDefaultDialog implements ChangeListener
The JTimeChooser class provides a dialog box for choosing a time.

Note that a valid I18NL10N database must be available!

The dialog box is modal, non-resizable and contains "Ok" and "Cancel" buttons to close it. Here's an example of a time chooser (Microsoft Windows L&F):

As can be seen, the time chooser's GUI consists of two main areas:

  • An analogue clock showing the currently selected hour, minute and second. An optional digital clock can also be shown in the clock's panel. Both clocks are updated in real-time.
  • Four JSpinners for selecting the hour, minute, second and millisecond.

There's also the exclamation checkbox that allows tracking (and selecting) the current time.

Depending on the desired functionality, the time chooser can be allowed to select only:

  • the hour and minute,
  • the hour, minute and second,
  • or the hour, minute, second and millisecond.

When the clock is showing HMS or HMS.ms, the user can also select the seconds by clicking on the clock's face.

When the user closes the time chooser's dialog box, its state should be queried as follows:

if (!myTimeChooser.isCancelled()) {
TimeStamp timeStamp = myTimeChooser.getSelectedTime();
// rest of code
}

Note that the system resources must be initialised (see JARResources.fSystemResources).

Note that this class cannot be subclassed!

Version:
01/05/2024
Author:
Sven Maerivoet
See Also:
  • Constructor Details

    • JTimeChooser

      public JTimeChooser(JFrame owner, String title, JDefaultDialog.EType dialogType, JTimeChooser.EType type, JTimeChooser.EUpdatingMethod updatingMethod, JTimeChooser.EDigitalClock digitalClock)
      Constructs a JTimeChooser object.

      Depending on the desired functionality, the time chooser can be allowed to select only:

      • the hour and minute,
      • the hour, minute and second,
      • or the hour, minute, second and millisecond.
      Parameters:
      owner - the frame in which this dialog is to be displayed
      title - the dialog's window title
      dialogType - the type of dialog
      type - the EType type of time chooser
      updatingMethod - an EUpdatingMethod flag indicating whether or not the clock's hands should be updated continuously or discretely
      digitalClock - an EDigitalClock flag indicating whether or not a digital indication of the current time should be shown
      See Also:
  • Method Details

    • stateChanged

      public void stateChanged(ChangeEvent e)
      Specified by:
      stateChanged in interface ChangeListener
    • actionPerformed

      public void actionPerformed(ActionEvent e)
      Description copied from class: JDefaultDialog
      The dialog box's action listener.

      Note that when overriding this method in a subclass, its parent should explicitly be called in order to guarantee the correct processing of the user's input ("Ok" and "Ok/Cancel" type of dialog boxes):

      super.actionPerformed(e);
      // rest of method's code

      Specified by:
      actionPerformed in interface ActionListener
      Overrides:
      actionPerformed in class JDefaultDialog
      Parameters:
      e - the ActionEvent that is received
    • getSelectedTime

      public TimeStamp getSelectedTime()
      Returns the currently selected time.
      Returns:
      the currently selected time
    • initialiseClass

      protected void initialiseClass(Object[] parameters)
      Description copied from class: JDefaultDialog
      Allows custom initialisation of a subclass's member fields.

      Note that the caller should specify null if no parameters are specified.

      Overrides:
      initialiseClass in class JDefaultDialog
      Parameters:
      parameters - an array of Objects
    • setupWindowTitle

      protected final String setupWindowTitle()
      Description copied from class: JDefaultDialog
      Sets up the window title of the dialog box.

      In order to obtain a custom dialog title, the caller should override this method (it returns null in the baseclass).

      Overrides:
      setupWindowTitle in class JDefaultDialog
      Returns:
      the window title of the dialog box
    • setupMainPanel

      protected void setupMainPanel(JPanel mainPanel)
      Description copied from class: JDefaultDialog
      Sets up the custom content in the dialog box.

      A subclass should typically create labels, inputfields, ... in the dialog boxes main panel, by overriding this method.

      Note that the mainPanel object is already constructed!

      Overrides:
      setupMainPanel in class JDefaultDialog
      Parameters:
      mainPanel - the area of the dialog box that is reserved for custom content