JavaBean Program Analysis
I want to introduce some of the main methods in htmlcalendarnotepad. I believe they will be helpful to you.
Public void setyear (INT year) // sets the year. The default value is the current year.
Public int getyear () // obtain the year. The default value is the current year.
// This is written in a standard Java program. Because a Java program is a class, this setxxx/getxxx is often written.
Public void setmonth (INT month) // sets the month (1-12). The default value is the current month.
Public int getmonth () // obtain the month (1-12). The default value is the current month.
Public void setstyle (INT style)
Public int getstyle ()
// Set/get the style of the calendar)
// It is the first day of a week on Sunday (htmlcalendarnotepad. sunday_first) or the first day of a week on Monday (htmlcalendarnotepad. monday_first)
// The default value is htmlcalendarnotepad. sunday_first.
Public void setlocale (locale LOC) // sets the regionCode(Locale), default value: locale. PRC
Public locale getlocale () // obtain the region code (locale). The default value is locale. PRC.
Public void setaction (INT day, string actionurl, string target_frame)
// Set a hyperlink to process the request. If any error occurs, this method returns an empty string.
// You can set a common URL, such as "http://www.yesky.com/action.jsp"
// Or a JavaScript function name, such as "myfunction"
// The date will be passed to the URL as a parameter or a string value to Javascript. The format is yyyymmdd.
// Target_frame can be a null string.
For example:
If setaction (21, "http://www.yesky.com/", "_ blank") is called ")
Hyperlink: <a href = "http://www.yesky.com /? Date = 20000621 "target = _ blank> 21 </a> 〉
Public void setactions (string actionurl, string target_frame)
// You can also set a hyperlink for each day of a month
Now let me share with you the attractive Bean: (htmlcalendarnotepad. Java ).
Import java. Text. dateformat;
Import java. Text. simpledateformat;
Import java. util .*;
Public class htmlcalendarnotepad
{
Public static final int monday_first = 1; // you can specify Monday as the first day of each week.
Public static final int sunday_first = 2; // you can specify Sunday as the first day of each week.
Private hashtable config;
Private Static final string mnth [] = {
"August ",
"July", "August", "September", "October", "November", "December"
};
Private int year;
Private int month;
Private int style;
Private string sfont;
Private locale LOC;
Private Static string newline = "\ n ";
Public htmlcalendarnotepad () // Constructor
{
Sfont = NULL;
Gregoriancalendar gcalendar = new gregoriancalendar (); // obtain the current calendar (gregoriancalendar)
Config = new hashtable (); // create a new hash table to store configuration information
Newline = system. getproperty ("line. separator ");
Style = 2; // set every week to Sunday as the first day
Month = gcalendar. Get (2); // get the month
Year = gcalendar. Get (1); // year
Loc = locale. PRC; // set the country name. The default value is the People's Republic of China.
}
Private string formatobject (string S, object OBJ)
{
String S1 = "";
If (OBJ! = NULL)
S1 = string. valueof (string. valueof (OBJ ));
If (S = NULL)
Return S1;
Else
Return S + S1 + "</font> 〉";
}
Private int getday (calendar) // gets the position of a specified day in the calendar.
{
If (style = 2)
Return calendar. Get (7)-1;
Else
Return (calendar. Get (7) + 5) % 7;
}
Public String gethtml ()
{
Gregoriancalendar gcalendar = new gregoriancalendar (year, month-1, 1 );
Gregoriancalendar gcalendar1 = new gregoriancalendar (2001, 3, 24 );
Simpledateformat = new simpledateformat ("eee", Loc );
// Set the abbreviation format. Eee is the abbreviation of a week, for example, sun. If eeee is Sunday.
Int I = month-1;
Int J = 0;
Stringbuffer = new stringbuffer (""); // create a new string buffer.
Stringbuffer. append ("<Table> <tr> \ n"); // Add <Table> <tr> On stringbuffer to prepare for table creation.
If (style = 2) // see the preceding description.
{
Stringbuffer. append ("<TH align = right>" + formatobject (sfont, simpledateformat. Format (gcalendar1.gettime () + "</Th> \ n ");
Gcalendar1.add (5, 1 );
For (int K = 1; k <7; k ++)
{
Stringbuffer. append ("<TH align = right>" + formatobject (sfont, simpledateformat. Format (gcalendar1.gettime () + "</Th> \ n ");
Gcalendar1.add (5, 1 );
}
}
Else
{
Gcalendar1.add (5, 1 );
Stringbuffer. append ("<TH align = right>" + formatobject (sfont, simpledateformat. Format (gcalendar1.gettime () + "</Th> \ n ");
For (int l = 2; L <8; l ++)
{
Gcalendar1.add (5, 1 );
Stringbuffer. append ("<TH align = right>" + formatobject (sfont, simpledateformat. Format (gcalendar1.gettime () + "</Th> \ n ");
}
}
Stringbuffer. append ("</tr> \ n ");
Int I1 = 0;
J = 0;
If (getday (gcalendar)> 0)
{
Stringbuffer. append ("<tr> 〉");
For (; I1 <getday (gcalendar); I1 ++)
{
Stringbuffer. append ("<TD align = right> 〉");
If (sfont! = NULL)
Stringbuffer. append (sfont + "</font> 〉");
Else
Stringbuffer. append ("");
Stringbuffer. append ("</TD> \ n ");
J ++;
}
}
For (; gcalendar. Get (2) = I; gcalendar. Add (5, 1 ))
{
Int J1 = gcalendar. Get (5 );
Int k1 = (I1 + J1) % 7;
If (k1 = 1)
{
Stringbuffer. append ("<tr>" + newline );
J = 0;
}
Stringbuffer. append ("<TD align = right> 〉");
J ++;
If (sfont! = NULL)
Stringbuffer. append (sfont );
String S;
If (S = (string) config. Get (string. valueof (J1 )))! = NULL)
{
Stringbuffer. append ("<a href = \"");
If (S. touppercase (). startswith ("htt") | S. indexof (".")> 0)
{
Stringbuffer. append (s );
If (S. indexof ("? ") <0)
Stringbuffer. append ("? Date = "+ stringdate (gcalendar ));
Else
Stringbuffer. append ("& date =" + stringdate (gcalendar ));
}
Else
{
Stringbuffer. append ("javascript:" + S + "('" + stringdate (gcalendar) + "');");
}
Stringbuffer. append ("\"");
If (S = (string) config. Get (J1 + "target "))! = NULL)
Stringbuffer. append ("target = \" "+ S + "\"");
Stringbuffer. append ("> ("〉");
Stringbuffer. append (gcalendar. Get (5 ));
Stringbuffer. append ("</a> \ n ");
}
Else
{
Stringbuffer. append (string. valueof (J1 ));
}
If (sfont! = NULL)
Stringbuffer. append ("</font> 〉");
Stringbuffer. append ("</TD> \ n ");
If (k1 = 0)
Stringbuffer. append ("</tr> \ n ");
}
If (j <7)
{
For (; j <7; j ++)
{
Stringbuffer. append ("<TD align = right> 〉");
If (sfont! = NULL)
Stringbuffer. append (sfont );
Stringbuffer. append ("");
If (sfont! = NULL)
Stringbuffer. append ("</font> 〉");
Stringbuffer. append ("</TD> \ n ");
}
Stringbuffer. append ("</tr> \ n ");
}
Stringbuffer. append ("</table> \ n ");
Return stringbuffer. tostring ();
}
Public locale getlocale () // obtain the region name
{
Return LOC;
}
Public int getyear () // obtain the year
{
Return htmlcalendaryear;
}
Public int getmonth () // obtain the monthly score
{
Return htmlcalendarmonth;
}
Public int getstyle () // get the calendar Style
{
Return htmlcalendarstyle;
}
// Set the URI of the action. The target_frame value can be _ blank, _ parent, _ top, and _ self.
Public void setaction (INT day, string actionuri, string target_frame)
{
If (actionuri! = NULL)
{
Config. Put (string. valueof (day), actionuri );
If (target_frame! = NULL & target_frame.length ()> 0)
Config. Put (day + "target", target_frame );
}
}
// Set hyperlinks for all days of a month
Public void setactions (string actionuri, string target_frame)
{
For (INT day = 1; day <=31; day ++)
Setaction (day, actionuri, target_frame );
}
// Set the region
Public void setlocale (locale)
{
Loc = locale;
}
// Set the year
Public void setyear (INT htmlcalendaryear)
{
If (htmlcalendaryear> 0)
{
Year = htmlcalendaryear;
Config. Clear ();
}
}
// Set the month
Public void setmonth (INT htmlcalendarmonth)
{
If (htmlcalendarmonth >=1 & htmlcalendarmonth <= 12)
{
Month = htmlcalendarmonth;
Config. Clear ();
}
}
// Set the calendar Style
Public void setstyle (INT htmlcalendarstyle)
{
Style = htmlcalendarstyle;
}
Private string stringdate (calendar)
{
String strday = string. valueof (calendar. Get (1 ));
Return strday + twodigits (calendar. Get (2) + 1) + twodigits (calendar ar. Get (5 ));
}
Private string twodigits (INT day) // Add 0 before 1-9 to align the numbers in the calendar
{
String stringday = string. valueof (day); // gets the value of day.
If (stringday. Length () = 1) // If the string length is 1
Return "0" + stringday; // Add zero before the string
Else
Return stringday;
}
}