On 9 Oct 2005 03:43:57 -0700,
wrote or quoted :
>Since all I wanted to achieve is to get the right number of rows in my
>MonthCalendarJTable, I simply calculated the value on my own. Here is
>the solution.
here is some code to generate an HTML calendar
package com.mindprod.lisa;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import com.mindprod.business.BigDate;
/**
* produces an HTML table calendar for any month
* suitable as a skeleton for a coming events schedule.
* put yyyy mm on command line.
*
* Requires BigDate from
*
http://mindprod.com/products.html#BIGDATE
*
* May be freely used for any purpose but military
*
* @author Roedy Green
* @author copyright (c) 2003-2005 Roedy Green, Canadian Mind Products
* @version 1.0
*/
public class CalMaker
{
/**
* Months of the year
*/
private static final String[] monthNames = {
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",};
/**
* days of the week 3 letter abbreviations in English. Index Sunday
= 0.
*/
private static final String[] shortDayName = { "sun" , "mon",
"tue", "wed" , "thu", "fri", "sat"};
/**
* outputs cal.html in current directory with an HTML table for
that month.
*
* @param args year month, e.g. 2003 11
* @exception IOException
*/
public static void main ( String[] args ) throws IOException
{
System.out.println("Results appear in cal.html" );
int year = Integer.parseInt( args [0] );
int month = Integer.parseInt( args [1] );
PrintWriter out = new PrintWriter ( new FileWriter( "cal.html"
));
out.println ( "<table width=\"620\" border=\"1\"
cellspacing=\"1\" bordercolor=\"#808080\" cellpadding=\"7\">" );
// header
out.println ( "<tr><th colspan=\"7\">Coming events for "
+ monthNames[ month-1]
+ " "
+ year
+ "</th></tr>" );
// label days of the week
out.println( "<tr>" );
for ( int i=0; i<7; i++ )
{
out.println( "<th>"
+ shortDayName[ i ]
+ "</th>" );
}
out.println( "</tr>" );
// dummy boxes before the month starts, possibly none.
BigDate firstOfMonth = new BigDate ( year, month, 1 );
int dummystarts = firstOfMonth.getDayOfWeek();
for ( int i=0; i<dummystarts; i++ )
{
if ( i== 0 )
{
out.println("<tr>");
}
out.println("<td> </td>");
}
// label days of the month
int daysInMonth = BigDate.daysInMonth( month, year );
for ( int day=1; day<=daysInMonth; day++ )
{
BigDate d = new BigDate ( year, month, day );
if ( d.getDayOfWeek() == 0 )
{
out.println("<tr>");
}
out.println( "<td width=\"90\"><span class=\"daynumber\">"
+ day
+
"</span> </td>");
if ( d.getDayOfWeek() == 6 )
{
out.println("</tr>");
}
}
// dummy boxes after the month ends, possibly none.
BigDate lastOfMonth = new BigDate ( year, month, daysInMonth );
int dummyStops = 6 - lastOfMonth.getDayOfWeek();
for ( int i=0; i<dummyStops; i++ )
{
out.println("<td> </td>");
if ( i == dummyStops-1 )
{
out.println("</tr>");
}
}
out.println ( "</table>" );
out.close();
}
}
--
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.