使用JavaBean创建您的网上日历本(2)_MySQL
JavaBean程序分析
我想把HtmlCalendarNotePad中的主要方法介绍一些,相信会大家有所帮助
public void setYear(int year) //设置年份 。默认值为当前的年份
public int getYear() //获得年份 。默认值为当前的年份
//这是标准Java程序写法,因为Java程序就是一个类所以经常写这种setXXX/getXXX
public void setMonth(int month) //设置月份(1-12),默认值为当前的月
public int getMonth() //获得月份(1-12),默认值为当前的月
public void setStyle(int style)
public int getStyle()
//设置/获得日历的样式(style)
//是以星期天为一星期的第一天HtmlCalendarNotePad.SUNDAY_FIRST还是以星期一为一星期的第一天 HtmlCalendarNotePad.MONDAY_FIRST
// 默认值为HtmlCalendarNotePad.SUNDAY_FIRST
public void setLocale(Locale loc) //设置地区代码(Locale), 默认值为Locale.PRC
public Locale getLocale() //获得地区代码(Locale), 默认值为Locale.PRC
public void setAction(int day, String actionUrl ,String target_frame)
//设置超链接,来处理请求。如果出了任何错误的话,该方法会返回一个空的字符串。
// 你可以设置一个普通的URL,如“http://www.yesky.com/action.jsp”
// 或者一个一个javascript 函数名, 如 “myFunction”
// 日期将被作为一个参数传给URL,或者作为一个字符串值传给 javascript. 格式是yyyymmdd.
// target_frame可以为空的字符串。
如:
如果调用setAction(21,"http://www.yesky.com/","_blank")
超链接为: 〈a href="http://www.yesky.com/?date=20000621" target=_blank〉21〈/a〉
public void setActions(String actionUrl, String target_frame)
//你也可以为一个月的每一天设置超链接
现在让我和大家一起来分享那颗诱人的豆子(Bean)吧:(HtmlCalendarNotePad.java)。
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.*;
public class HtmlCalendarNotePad
{
public static final int MONDAY_FIRST = 1; //设置每星期是以星期一为第一天
public static final int SUNDAY_FIRST = 2; //设置每星期是以星期日为第一天
private Hashtable config;
private static final String Mnth[] = {
"一月", "二月", "三月", "四月", "五月", "六月",
"七月", "八月", "九月", "十月", "十一月", "十二月"
};
private int year;
private int month;
private int style;
private String sFont;
private Locale loc;
private static String NEWLINE = "\n";
public HtmlCalendarNotePad () //构造函数
{
sFont = null;
GregorianCalendar gCalendar = new GregorianCalendar(); //取得当前的日历(格里高里历)
config = new Hashtable(); //创建新的哈希表储存配置信息
NEWLINE = System.getProperty("line.separator");
style = 2; //设置每星期是以星期日为第一天
month = gCalendar.get(2); //取得月份
year = gCalendar.get(1); //取的年份
loc = Locale.PRC; //设置国家名,默认为中华人民共和国
}
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 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 simpledateformat = new SimpleDateFormat("EEE", loc);
//设置缩写格式,EEE是星期的缩写,如 Sun, 若EEEE则为Sunday。
int i = month - 1;
int j = 0;
StringBuffer stringbuffer = new StringBuffer(""); //创建新的字符串缓冲区
stringbuffer.append("〈table〉〈tr〉\n"); //在stringbuffer上添加〈table〉〈tr〉,为创建表格作准备
if(style == 2) //见上解释
{
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() //获取地区名
{
return loc;
}
public int getYear() //取得年份
{
return htmlCalendarYear;
}
public int getMonth() //取得月分
{
return htmlCalendarMonth;
}
public int getStyle() //取得日历的样式
{
return htmlCalendarStyle;
}
//设置动作的URI,target_frame 的值可以为_blank、 _parent、 _top、 _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);
}
}
//设置一个月的所有天的超链接
public void setActions(String actionUri, String target_frame)
{
for(int day = 1; day 〈= 31; day++)
setAction(day, actionUri, target_frame);
}
//设置地区
public void setLocale(Locale locale)
{
loc = locale;
}
//设置年份
public void setYear(int htmlCalendarYear)
{
if(htmlCalendarYear 〉 0)
{
year = htmlCalendarYear;
config.clear();
}
}
//设置月份
public void setMonth(int htmlCalendarMonth)
{
if(htmlCalendarMonth 〉= 1 && htmlCalendarMonth 〈= 12)
{
month = htmlCalendarMonth;
config.clear();
}
}
//设置日历的样式
public void setStyle(int htmlCalendarStyle)
{
style = htmlCalendarStyle;
}
private String stringDate(Calendar calendar)
{
String strDay = String.valueOf(calendar.get(1));
return strDay + twoDigits(calendar.get(2) + 1) + twoDigits(calendar.get(5));
}
private String twoDigits(int day) //为了日历中数字能够对齐,所以1-9 前将加0
{
String stringDay = String.valueOf(day); //取得day的值
if(stringDay.length() == 1) //如果字符串长度为1
return "0" + stringDay; //则在字符串前加零
else
return stringDay;
}
}

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



An important tool for organizing your daily work and routine in Windows 11 is the display of time and date in the taskbar. This feature is usually located in the lower right corner of the screen and gives you instant access to the time and date. By clicking this area, you can bring up your calendar, making it easier to check upcoming appointments and dates without having to open a separate app. However, if you use multiple monitors, you may run into issues with this feature. Specifically, while the clock and date appear on the taskbar on all connected monitors, the ability to click the date and time on a second monitor to display the calendar is unavailable. As of now, this feature only works on the main display - it's unlike Windows 10, where clicking on any

CrystalDiskMark is a small HDD benchmark tool for hard drives that quickly measures sequential and random read/write speeds. Next, let the editor introduce CrystalDiskMark to you and how to use crystaldiskmark~ 1. Introduction to CrystalDiskMark CrystalDiskMark is a widely used disk performance testing tool used to evaluate the read and write speed and performance of mechanical hard drives and solid-state drives (SSD). Random I/O performance. It is a free Windows application and provides a user-friendly interface and various test modes to evaluate different aspects of hard drive performance and is widely used in hardware reviews

foobar2000 is a software that can listen to music resources at any time. It brings you all kinds of music with lossless sound quality. The enhanced version of the music player allows you to get a more comprehensive and comfortable music experience. Its design concept is to play the advanced audio on the computer The device is transplanted to mobile phones to provide a more convenient and efficient music playback experience. The interface design is simple, clear and easy to use. It adopts a minimalist design style without too many decorations and cumbersome operations to get started quickly. It also supports a variety of skins and Theme, personalize settings according to your own preferences, and create an exclusive music player that supports the playback of multiple audio formats. It also supports the audio gain function to adjust the volume according to your own hearing conditions to avoid hearing damage caused by excessive volume. Next, let me help you

If your Outlook calendar cannot sync with Google Calendar, Teams, iPhone, Android, Zoom, Office account, etc., please follow the steps below to resolve the issue. The calendar app can be connected to other calendar services such as Google Calendar, iPhone, Android, Microsoft Office 365, etc. This is very useful because it can sync automatically. But what if OutlookCalendar fails to sync with third-party calendars? Possible reasons could be selecting the wrong calendar for synchronization, calendar not visible, background application interference, outdated Outlook application or calendar application, etc. Preliminary fix for Outlook calendar not syncing

NetEase Mailbox, as an email address widely used by Chinese netizens, has always won the trust of users with its stable and efficient services. NetEase Mailbox Master is an email software specially created for mobile phone users. It greatly simplifies the process of sending and receiving emails and makes our email processing more convenient. So how to use NetEase Mailbox Master, and what specific functions it has. Below, the editor of this site will give you a detailed introduction, hoping to help you! First, you can search and download the NetEase Mailbox Master app in the mobile app store. Search for "NetEase Mailbox Master" in App Store or Baidu Mobile Assistant, and then follow the prompts to install it. After the download and installation is completed, we open the NetEase email account and log in. The login interface is as shown below

Cloud storage has become an indispensable part of our daily life and work nowadays. As one of the leading cloud storage services in China, Baidu Netdisk has won the favor of a large number of users with its powerful storage functions, efficient transmission speed and convenient operation experience. And whether you want to back up important files, share information, watch videos online, or listen to music, Baidu Cloud Disk can meet your needs. However, many users may not understand the specific use method of Baidu Netdisk app, so this tutorial will introduce in detail how to use Baidu Netdisk app. Users who are still confused can follow this article to learn more. ! How to use Baidu Cloud Network Disk: 1. Installation First, when downloading and installing Baidu Cloud software, please select the custom installation option.

MetaMask (also called Little Fox Wallet in Chinese) is a free and well-received encryption wallet software. Currently, BTCC supports binding to the MetaMask wallet. After binding, you can use the MetaMask wallet to quickly log in, store value, buy coins, etc., and you can also get 20 USDT trial bonus for the first time binding. In the BTCCMetaMask wallet tutorial, we will introduce in detail how to register and use MetaMask, and how to bind and use the Little Fox wallet in BTCC. What is MetaMask wallet? With over 30 million users, MetaMask Little Fox Wallet is one of the most popular cryptocurrency wallets today. It is free to use and can be installed on the network as an extension

Title: Realme Phone Beginner’s Guide: How to Create Folders on Realme Phone? In today's society, mobile phones have become an indispensable tool in people's lives. As a popular smartphone brand, Realme Phone is loved by users for its simple and practical operating system. In the process of using Realme phones, many people may encounter situations where they need to organize files and applications on their phones, and creating folders is an effective way. This article will introduce how to create folders on Realme phones to help users better manage their phone content. No.
