Interface Date_selector

  • All Known Implementing Classes:
    Date_selector_dialog, Date_selector_panel, Navigable_date_selector, Time_date_selector, Titled_date_selector

    public interface Date_selector
    An interface for Date selection.

    See Date_selector_panel for a discussion of how date selectors look and work. This interface defines the public methods of that class to allow for the use of a Gang-of-Four Decorator to add optional labels.

    Most of the interface methods have to do with action-listeners support. The listeners are notified in two situations, which can be distinguished from one another by calling AWTEvent.getID():

    getID() Returns: Description:
    CHANGE_ACTION This event is sent when the calendar panel changes the displayed month or year (tyically because some sort of navigator bar asked it to). Call event.getActionCommand() to get a string holding the current (after the scroll) month and year. You can also call get_current_date() to get get the date the user selected.
    SELECT_ACTION Sent every time the user clicks on a date. Call event.getActionCommand() to get a string representing the selected date. (This string takes the same form as the one returned by Date.toString().) You can also call get_selected_date() to get get the date the user selected.

    The following example demonstrates how to create a single JPanel that contains a title displaying the name of the current month and year as well as a calendar for that date. The ActionListener automatically updates the label every time the user navigates to another month. (You will rarely have to do this, since the Titled_date_selector class will handle exactly that problem for you, but the example demonstrates the technique.)

     private static JPanel create_calendar_pane(Date_selector s) {
      JPanel panel = new JPanel();
      panel.setLayout(new BorderLayout());
      final JLabel month = new JLabel("MMM YYYY");
      s.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          if (e.getID() == Date_selector.CHANGE_ACTION)
      panel.add(month, BorderLayout.NORTH);
      panel.add(s, BorderLayout.CENTER);
      return panel;

    Classes that implement this interface must also extend Container or some Container derivative. (You can't mandate this in the compiler because Container is not an interface, so can't be a base class of Date_selector.)

    See Also:
    Date_selector_panel, Date_selector_dialog
    • Method Detail

      • addActionListener

        void addActionListener​(java.awt.event.ActionListener l)
      • removeActionListener

        void removeActionListener​(java.awt.event.ActionListener l)
      • get_selected_date

        java.util.Date get_selected_date()
      • get_current_date

        java.util.Date get_current_date()
      • set_selected_date

        void set_selected_date​(java.util.Date d)
      • roll

        void roll​(int flag,
                  boolean up)
        Must work just like Calendar.roll(int, boolean)
      • get

        int get​(int flag)
        Must work just like Calendar.get(int)
      • getComponent

        javax.swing.JComponent getComponent()