基于java的桌面日历程序源码

  • 格式:txt
  • 大小:6.87 KB
  • 文档页数:3

for(int i=0;i<42;i++)
{
labelDay[i].setText(day[i]);
}
}
public void setMonth(int month)
{
this.month=month;
}
public int getMonth()
{
JButton titleName[]=new JButton[7];
JButton button = new JButton();
String name[]={"日","一","二","三", "四","五","六"};
JButton nextMonth,previousMonth;
import java.util.Calendar;
public class CalendarBean
{
String day[];
int year=2005,month=0;
public void setYear(int year)
if(month==1||month==3||month==5||month==7
||month==8||month==10||month==12)
{
day=31;
}
titleName[i]=new JButton(name[i]);
pCenter.add(titleName[i]);
}
//pCenter添加组件labelDay[i]
JLabel lbl2=new JLabel(" ");
public CalendarFrame()
{
JPanel pCenter=new JPanel();
//将pCenter的布局设置为7行7列的GridLayout 布局。
//判断平年与闰年
if(month==2)
{
if(((year%4==0)&&(year%100!=0))||(year%400==0))
{
{
this.year=year;
}
public int getYear()
{
return year;
}
}
for(int i=week,n=1;i<week+day;i++)
{
a[i]=String.valueOf(n) ;
n++;
calendar.setMonth(month);
String day[]=calendar.getCalendar();
for(int i=0;i<42;i++)
{
labelDay[i].setText(day[i]);
//注册监听器
nextMonth.addActionListener(this);
previousMonth.addActionListener(this);
button.addActionListener(this);
month=month+1;
if(month>12)
month=1;
calendar.setMonth(month);
String day[]=calendar.getCalendar();
date.set(year,month-1,1);
int week=date.get(Calendar.DAY_OF_WEEK)-1;
int day=0;
//判断大月份
pCenter.setLayout(new GridLayout(7,7));
//pCenter添加组件titleName[i]
for(int i=0;i<7;i++)
{
add(scrollPane,BorderLayout.CENTER);// 窗口添加scrollPane在中心区域
add(pNorth,BorderLayout.NORTH);// 窗口添加pNortBorderLayout.SOUTH);// 窗口添加pSouth 在南区域。
JPanel pNorth=new JPanel(),
pSouth=new JPanel();
pNorth.add(showMessage);
pNorth.add(lbl2);
pNorth.add(previousMonth);
pNorth.add(nextMonth);
pSouth.add(lbl1);
pSouth.add(text);
pSouth.add(button);
int year=1996,month=1; //启动程序显示的日期信息
CalendarBean calendar;
JLabel showMessage=new JLabel("",JLabel.CENTER);
JLabel lbl1 = new JLabel("请输入年份:");
day=29;
}
else
{
day=28;
}
}
text.addActionListener(this);
calendar=new CalendarBean();
calendar.setYear(year);
public class CalendarFrame extends JFrame implements ActionListener
{
JLabel labelDay[]=new JLabel[42];
JTextField text=new JTextField(10);
else if(e.getSource()==previousMonth)
{
month=month-1;
for(int i=0;i<42;i++)
{
labelDay[i]=new JLabel("",JLabel.CENTER);
pCenter.add(labelDay[i]);
showMessage.setText("日历:"+calendar.getYear()+"年"+ calendar.getMonth()+"月" );
ScrollPane scrollPane=new ScrollPane();
scrollPane.add(pCenter);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==nextMonth)
{
}
return a;
}
}
CalendarFrame.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
//判断小月
if(month==4||month==6||month==9||month==11)
{
day=30;
}
}
nextMonth=new JButton("下月");
previousMonth=new JButton("上月");
button=new JButton("确定");
return month;
}
public String[] getCalendar()
{
String a[]=new String[42];
Calendar date=Calendar.getInstance();

下载文档原格式

  / 3