public interface Date_selector
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. |
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.)
Date_selector_panel
,
Date_selector_dialog
Modifier and Type | Field and Description |
---|---|
static int |
CHANGE_ACTION |
static int |
COMMIT_ACTION |
static int |
SELECT_ACTION |
Modifier and Type | Method and Description |
---|---|
void |
addActionListener(java.awt.event.ActionListener l) |
java.util.Date |
get_current_date() |
java.util.Date |
get_selected_date() |
int |
get(int flag)
Must work just like
Calendar.get(int) |
javax.swing.JComponent |
getComponent() |
void |
removeActionListener(java.awt.event.ActionListener l) |
void |
roll(int flag,
boolean up)
Must work just like
Calendar.roll(int,boolean) |
void |
set_selected_date(java.util.Date d) |
static final int CHANGE_ACTION
static final int SELECT_ACTION
static final int COMMIT_ACTION
void addActionListener(java.awt.event.ActionListener l)
void removeActionListener(java.awt.event.ActionListener l)
java.util.Date get_selected_date()
java.util.Date get_current_date()
void set_selected_date(java.util.Date d)
void roll(int flag, boolean up)
Calendar.roll(int,boolean)
int get(int flag)
Calendar.get(int)
javax.swing.JComponent getComponent()