Java Reference
In-Depth Information
}
public static int daysInMonth (Calendar calendar) {
int year = calendar.get (Calendar.YEAR);
int month = calendar.get (Calendar.MONTH);
int days = daysInMonth [month-Calendar.JANUARY];
if ((month == Calendar.FEBRUARY) && (year % 4 == 0)
&& !(year % 100 == 0) || (year % 400 == 0))
days++;
return days;
}
public void setDate (Date date) {
calendar.setTime (date);
repaint();
}
public Calendar getCalendar() {
return calendar;
}
public Date getDate() {
return calendar.getTime();
}
public Dimension getMinimumSize() {
return getPreferredSize();
}
public Dimension getPreferredSize() {
FontMetrics fm = getFontMetrics (getFont());
return new Dimension ((fm.stringWidth ("88") + 1) * 7 + 1,
(fm.getHeight() + 1) * 7 + 1);
}
public void mouseEntered (MouseEvent ev) {}
public void mouseExited (MouseEvent ev) {}
public void mousePressed (MouseEvent ev) {}
public void mouseReleased (MouseEvent ev) {}
public void mouseClicked (MouseEvent ev) {
int x = (ev.getX() - left) / cellWidth;
int y = (ev.getY() - top) / cellHeight - 1;
int index = x + 7 * y - firstDay + 1;
if (index > 0 && index <= daysInMonth (calendar))
calendar.set (Calendar.DAY_OF_MONTH, index);
repaint();
}
}
Search WWH ::




Custom Search