Interface Date_selector
- All Known Implementing Classes:
Date_selector_dialog
,Date_selector_panel
,Navigable_date_selector
,Time_date_selector
,Titled_date_selector
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) month.setText(e.getActionCommand()); else System.out.println(e.getActionCommand()); } }); 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:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Method Summary
Modifier and TypeMethodDescriptionvoid
int
get
(int flag) Must work just likeCalendar.get(int)
void
void
roll
(int flag, boolean up) Must work just likeCalendar.roll(int, boolean)
void
-
Field Details
-
CHANGE_ACTION
static final int CHANGE_ACTION- See Also:
-
SELECT_ACTION
static final int SELECT_ACTION- See Also:
-
COMMIT_ACTION
static final int COMMIT_ACTION- See Also:
-
-
Method Details
-
addActionListener
-
removeActionListener
-
get_selected_date
Date get_selected_date() -
get_current_date
Date get_current_date() -
set_selected_date
-
roll
void roll(int flag, boolean up) Must work just likeCalendar.roll(int, boolean)
-
get
int get(int flag) Must work just likeCalendar.get(int)
-
getComponent
JComponent getComponent() -
getInnerSelector
Date_selector getInnerSelector()- Returns:
- A reference to any 'inner' selector inside this
Date_selector
implementation. May returnthis
.
-