Class tea.set.Calendar
All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.Calendar

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----tea.set.Calendar

public class Calendar
extends Canvas
Calendar widget provides an interface to manipulate one month calendar. It handles calendar related calculation automatically. There are a number of options to control the apperance of the calendar. Users can interact with the calendar by selecting one day or a day range. One or more days can be highlighted from the program. Calendar widget calculates the optimum size to display a calendar. But if the widget is resized to a size other than the default, the layout of the calendar is automatically recalculated to lay the days out evenly over the available space. Since setYear() and setMonth() clears all selections, select() should be called after these functions.

Variable Index

 o ALL
Display year, month name, and weekday.
 o MONTH_WEEK
Display weekday header and month name.
 o NO_TITLE
Display only days.
 o WEEK
Display weekday header (Monday - Sunday).

Constructor Index

 o Calendar()
Create a new calendar containing the current month.
 o Calendar(int, int)
Create a monthly calendar for year/month.

Method Index

 o action(Event, Object)
Action routine is called when a day or a day range is selected.
 o clear()
Clear any outstanding selection.
 o compareTo(Calendar)
Return the difference in month between this and mon.
 o dayOfWeek(int, int, int)
Return the day of week for year/month/day.
 o daysInMonth(int, int)
Return the number of days in month.
 o dehighlight(int)
De-highlight the specified day.
 o dehighlight(int, int)
De-highlight the specified days in the range, inclusive.
 o equals(Object)
Return true if the Calendars have same year and month.
 o getEndDay()
Return the end day (inclusive) of a selected date range.
 o getMonth()
Return the month of the calendar.
 o getMonthName(int)
Return the three letter month name for month m.
 o getStartDay()
Get the start day of a selected date range.
 o getYear()
Return the year of this calendar.
 o highlight(int)
Highlight the specified day.
 o highlight(int, int)
Highlight the specified days in the range, inclusive.
 o isHighlighted(int)
Return true if the specified day is highlighted.
 o minimumSize()
Return the minimum size of the widget.
 o mouseDown(Event, int, int)
Set the starting selection point to the day where the mouse pointer is in.
 o mouseDrag(Event, int, int)
Day range selection.
 o mouseUp(Event, int, int)
Set the ending point of the selection to the day where the mouse pointer is in.
 o paint(Graphics)
Paint the calendar.
 o preferredSize()
Return the preferred size of the widget.
 o select(int)
Select the specified day.
 o select(int, int)
Select the specified day range.
 o selectAll()
Mark the entire month as selected.
 o setHighlight(Color)
Set the highlight color.
 o setMonth(int)
Set the month of the calendar.
 o setTitle(int)
Set the title option to either no title, weekday only, month and weekday, or all.
 o setYear(int)
Set the year of the calendar.
 o toString()
Converts to a string representation.
 o update(Graphics)
For double buffering.

Variables

 o NO_TITLE
  public final static int NO_TITLE
Display only days.
 o WEEK
  public final static int WEEK
Display weekday header (Monday - Sunday).
 o MONTH_WEEK
  public final static int MONTH_WEEK
Display weekday header and month name.
 o ALL
  public final static int ALL
Display year, month name, and weekday.

Constructors

 o Calendar
  public Calendar()
Create a new calendar containing the current month.
 o Calendar
  public Calendar(int year,
                  int month)
Create a monthly calendar for year/month. Year starts from 1900, so pass 96 for 1996. Month starts from 0 to 11, corresponding to Jan to Dec respectively.
Parameters:
year - calendar year, year subtract 1900.
month - calendar month, starts from 0.

Methods

 o setTitle
  public void setTitle(int flag)
Set the title option to either no title, weekday only, month and weekday, or all. This causes a repaint.
Parameters:
flag - title flag, one of the title option values.
 o setYear
  public void setYear(int year)
Set the year of the calendar. This causes a repaint.
Parameters:
year - calendar year.
 o getYear
  public int getYear()
Return the year of this calendar.
Returns:
calendar year.
 o setMonth
  public void setMonth(int month)
Set the month of the calendar. This causes a repaint.
Parameters:
month - calendar month.
 o getMonth
  public int getMonth()
Return the month of the calendar.
Returns:
calendar month, 0-11.
 o highlight
  public void highlight(int day)
Highlight the specified day.
Parameters:
day - day number, starts from 1.
 o highlight
  public void highlight(int sday,
                        int eday)
Highlight the specified days in the range, inclusive.
Parameters:
sday - starting day of highlight range, starts from 1.
eday - ending day of highlight range, starts from 1.
 o dehighlight
  public void dehighlight(int day)
De-highlight the specified day.
Parameters:
day - number starts from 1.
 o dehighlight
  public void dehighlight(int sday,
                          int eday)
De-highlight the specified days in the range, inclusive.
Parameters:
sday - starting day number of range, starts from 1.
eday - ending day number of range, starts from 1.
 o isHighlighted
  public boolean isHighlighted(int day)
Return true if the specified day is highlighted.
Parameters:
day - day number starts from 1.
 o setHighlight
  public void setHighlight(Color c)
Set the highlight color. Defaults to red.
Parameters:
c - highlight color.
 o minimumSize
  public Dimension minimumSize()
Return the minimum size of the widget.
Returns:
minimum size of calendar.
Overrides:
minimumSize in class Component
 o preferredSize
  public Dimension preferredSize()
Return the preferred size of the widget.
Parameters:
preferred - size of calendar.
Overrides:
preferredSize in class Component
 o action
  public boolean action(Event e,
                        Object o)
Action routine is called when a day or a day range is selected. The argument object is a reference to Calendar itself.
Parameters:
e - event object.
o - event argument object.
Returns:
always false.
Overrides:
action in class Component
 o getStartDay
  public int getStartDay()
Get the start day of a selected date range. Return -1 if no selection is made. Day number starts at 1.
Returns:
day number of the starting point of selected day range. -1 if no selection is made.
 o getEndDay
  public int getEndDay()
Return the end day (inclusive) of a selected date range. Return -1 if no selection is made. Day number starts at 1.
Returns:
day number of the ending point of selected day range. -1 if no selection is made.
 o clear
  public void clear()
Clear any outstanding selection. This could cause a repaint if there is a range selected.
 o select
  public void select(int day)
Select the specified day. No event is generated by this function.
Parameters:
day - number starts from 1.
 o select
  public void select(int sday,
                     int eday)
Select the specified day range. No event is generated by this funciton.
Parameters:
sday - starting day of range, starts from 1.
eday - ending day of range, starts from 1.
 o selectAll
  public void selectAll()
Mark the entire month as selected.
 o equals
  public boolean equals(Object mon)
Return true if the Calendars have same year and month.
Parameters:
mon - Calendar object for comparison.
Returns:
true if calendar year and month are same.
Overrides:
equals in class Object
 o compareTo
  public int compareTo(Calendar mon)
Return the difference in month between this and mon.
 o toString
  public String toString()
Converts to a string representation.
Returns:
string representation of canlendar.
Overrides:
toString in class Component
 o update
  public void update(Graphics g)
For double buffering.
Parameters:
g - Graphics content of this component.
Overrides:
update in class Component
 o paint
  public void paint(Graphics g)
Paint the calendar.
Parameters:
g - Graphics content of this component.
Overrides:
paint in class Canvas
 o mouseDown
  public boolean mouseDown(Event e,
                           int x,
                           int y)
Set the starting selection point to the day where the mouse pointer is in.
Parameters:
e - event object.
x - x coordinate of the mouse click point.
y - y coordinate of the mouse click point.
Overrides:
mouseDown in class Component
 o mouseUp
  public boolean mouseUp(Event e,
                         int x,
                         int y)
Set the ending point of the selection to the day where the mouse pointer is in.
Parameters:
e - event object.
x - x coordinate of the mouse click point.
y - y coordinate of the mouse click point.
Overrides:
mouseUp in class Component
 o mouseDrag
  public boolean mouseDrag(Event e,
                           int x,
                           int y)
Day range selection.
Parameters:
e - event object.
x - x coordinate of the mouse click point.
y - y coordinate of the mouse click point.
Overrides:
mouseDrag in class Component
 o daysInMonth
  public static int daysInMonth(int year,
                                int month)
Return the number of days in month. Month starts from zero(0).
Parameters:
year - year is the year minus 1900.
month - month starts from 0-11.
Returns:
number of days in the month.
 o dayOfWeek
  public static int dayOfWeek(int year,
                              int month,
                              int day)
Return the day of week for year/month/day. Sunday is 0.
Parameters:
year - year is the year minus 1900.
month - month starts from 0-11.
day - day starts from 1.
Returns:
0 for Sunday, 1 for monday, and so on.
 o getMonthName
  public static String getMonthName(int m)
Return the three letter month name for month m. Month starts from 0.
Parameters:
m - month number, starts from 0.
Returns:
month name.

All Packages  Class Hierarchy  This Package  Previous  Next  Index