Java日历的小程序
Java写的日历小程序,算法效率虽然不算很高,却是简单实用的
CalendarBean.java
import java.util.Calendar;
public class CalendarBean
{
String day[];
int year=2005,month=0;
public void setYear(int year)
{
this.year=year;
}
public int getYear()
{
return year;
}
public void setMonth(int month)
{
this.month=month;
}
public int getMonth()
{
return month;
}
public String[] getCalendar()
{
String a[]=new String[42];
Calendar date=Calendar.getInstance();
date.set(year,month-1,1);
int week=date.get(Calendar.DAY_OF_WEEK)-1;
int day=0;
//判断大月份
if(month==1||month==3||month==5||month==7
||month==8||month==10||month==12)
{
day=31;
}
//判断小月
if(month==4||month==6||month==9||month==11)
{
day=30;
}
//判断平年与闰年
if(month==2)
{
if(((year%4==0)&&(year%100!=0))||(year%400==0))
{
day=29;
}
else
{
day=28;
}
}
for(int i=week,n=1;i<week+day;i++)
{
a[i]=String.valueOf(n) ;
n++;
}
return a;
}
}
CalendarFrame.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CalendarFrame extends JFrame implements ActionListener
{
JLabel labelDay[]=new JLabel[42];
JTextField text=new JTextField(10);
JButton titleName[]=new JButton[7];
JButton button = new JButton();
String name[]={"日","一","二","三", "四","五","六"};
JButton nextMonth,previousMonth;
int year=1996,month=1; //启动程序显示的日期信息
CalendarBean calendar;
JLabel showMessage=new JLabel("",JLabel.CENTER);
JLabel lbl1 = new JLabel("请输入年份:");
JLabel lbl2=new JLabel(" ");
public CalendarFrame()
{
JPanel pCenter=new JPanel();
 
补充:软件开发 , Java ,