Class DateChooser

All Implemented Interfaces:
ActionListener, FocusListener, KeyListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class DateChooser extends JDialog implements ActionListener, FocusListener, KeyListener
Hovanes Gambaryan Henry Demirchian CSUN, CS 585 Professor Mike Barnes December 06, 2000

DateChooser class is a general GUI based date chooser. It allows the user to select an instance of defined in package.

Programming API is similar to JFC's JColorChooser or JFileChooser. This class can be used in any application to enable the user to select a date from a visually displayed calendar.

There is a lot of improvements that can be done over this class in areas of functionality, usability, and appearance. But as is, the class can be easily used from within any Java program.

Typical usage is like:

// initial date LocalDate date = LocalDate.now()

// The owner is the JFrame of the application ("AppClass.this")

// show the date chooser DateChooser dc = new DateChooser(owner, date);

// user can either choose a date or cancel by closing if (dc.showDateChooser() == DateChooser.OK_OPTION) { date = dc.getDate(); }

See Also:
  • Field Details

  • Constructor Details

    • DateChooser

      public DateChooser(JDialog parentDialog, LocalDate date)
      Constructor for DateChooser which has parent dialog
      Parameters:
      parentDialog - JDialog istance. Dialog that owns this
      date - LocalDate instance that will be the initial date for this dialog
    • DateChooser

      public DateChooser(JFrame owner, LocalDate date)
      Constructor for DateChooser which does not have a parent dialog
      Parameters:
      owner - JFrame instance, owner of DateChooser dialog
      date - LocalDate instance that will be the initial date for this dialog
  • Method Details

    • getDate

      public LocalDate getDate()
      Return the last selected date for this instance of DateChooser
    • showDateChooser

      public int showDateChooser()
      Displays a DateChooser dialog on the screen. If a new date is selected returnsor OK_OPTION. If the action is canceled returns CANCEL_OPTION. Both of the returned values are defined as static constants.
    • actionPerformed

      public void actionPerformed(ActionEvent event)
      Action handler for this dialog, which handles all the button presses.
      Specified by:
      actionPerformed in interface ActionListener
      Parameters:
      event - ActionEvent
    • focusGained

      public void focusGained(FocusEvent event)
      Select all text in the date field when it gains the focus.
      Specified by:
      focusGained in interface FocusListener
      Parameters:
      event - FocusEvent
    • focusLost

      public void focusLost(FocusEvent event)
      Specified by:
      focusLost in interface FocusListener
    • keyTyped

      public void keyTyped(KeyEvent event)
      Specified by:
      keyTyped in interface KeyListener
    • keyPressed

      public void keyPressed(KeyEvent event)
      Specified by:
      keyPressed in interface KeyListener
    • keyReleased

      public void keyReleased(KeyEvent event)
      Specified by:
      keyReleased in interface KeyListener