Java Reference
In-Depth Information
calendar.set (Calendar.MONTH,
monthChoice.getSelectedIndex() +
Calendar.JANUARY);
propagate();
}
public void actionPerformed (ActionEvent ev) {
if (ev.getSource() == buttonPlus)
calendar.set (Calendar.YEAR, calendar.get (Calendar.YEAR)
+ 1);
else if (ev.getSource() == buttonMinus)
calendar.set (Calendar.YEAR, calendar.get (Calendar.YEAR)
- 1);
propagate();
}
}
Listing 9.5 CalendarCanvas.java —The CalendarCanvas Class Source Code
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class CalendarCanvas extends Component implements
MouseListener {
Calendar calendar = Calendar.getInstance();
private static String[] days
= {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"} ;
private static int daysInMonth[]
= {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} ;
int cellWidth;
int cellHeight;
int totalWidth;
int totalHeight;
int left;
int top;
int firstDay;
public CalendarCanvas() {
addMouseListener(this);
}
public void paint(Graphics g) {
cellWidth = (getWidth() - 1) / 7;
cellHeight = (getHeight() - 1) / 7;
totalWidth = 7 * cellWidth + 1;
totalHeight = 7 * cellHeight + 1;
left = (getWidth() - totalWidth) / 2;
top = (getHeight() - totalHeight) / 2;
 
Search WWH ::




Custom Search