int y_position = 60;
int y_add = 20; // The 'y' (or vertical) display position of each date
// is moved by this amount.
int x_add = 20; // similarly for the horizontal 'x'.
int days = 31; // Default number of days - used in most of the months
int startday = 0;
String month_string = "";
// August
startday = 2;
month_string = "August 2000";
// This will shift the printing of the first day of the month along by
// the relevant number of days... E.g. Tuesday in the 2nd position, wed = 3rd
int x_position = 20 + x_add * startday;
// Select the Courier font, in which all the characters have equal spaces
g.setFont(new Font("Courier",Font.PLAIN,12));
// Display the month
g.drawString( month_string, 20, 20);
// Display the days
g.drawString("M T W T F S S", 40, 40);
// Loop through all the days of the month
for (int date = 1; date <= days; date++)
{
g.drawString(date + " " , x_position , y_position);
x_position = x_position + x_add; // Shift the display position for the next date
startday++; // step to the next day
if ( startday > 7) // See if the day is greater than 7 (Sunday)
{
x_position = 40; // Yes it is, move the x display position back
y_position = y_position + y_add; // and move the y display position down.
startday = 1; // Put the day back to 1 (Monday)
} // End of if startday > 7
} // End of for