基于Java的日历记事本 联系客服

发布时间 : 星期六 文章基于Java的日历记事本更新完毕开始阅读4f92947d852458fb770b567c

软件课程设计设计(论文)用纸

参考文献

[1]耿祥义,张跃平 Java2实用教程(第三版)[M] . 北京:清华大学出版社, 2006 [2]耿祥义 Java课程设计(第三版)[M] . 北京:清华大学出版社, 2004

[3]张跃平 Java2实用教程实验指导与习题解答(第三版)[M]. 北京:清华大学出版社, 2004

[4]Jacquie Barker,Java面向对象编程指南,电子工业出版社,2001

[5]孙全党,王吴迪 赵枫朝,Java程序设计应用教程,电子工业出版社,2006.2 [6]赵玉阳,Java从入门到精通,清华大学出版社,2006.8 [7]肖磊,李钟尉,Java实用教程,人民邮电出版社,2008.5 [8]李尊朝 Java语言程序设计 北京:中国铁道出版社,2004.2 [9]王鹏,何昀峰 Java图形界面开发 北京:清华大学出版社 2008

[10]叶核亚 JAVA2程序设计实用教程[M](第2版).北京:电子工业出版社 2008.4

21

软件课程设计设计(论文)用纸

附录

主类 CalendarPad: CalendarPad。Java import java.util.Calendar; import javax.swing.*; import java.awt.*;

import java.awt.event.*; import java.io.*;

import java.util.Hashtable;

public class CalendarPad extends JFrame implements MouseListener {

int year,month,day;

Hashtable hashtable; File file; JTextField showDay[]; JLabel title[]; Calendar 日历; int 星期几;

NotePad notepad=null; Month 负责改变月; Year 负责改变年;

String 星期[]={\星期日\星期一\星期二\星期三\星期四\星期五\星期六\

JPanel leftPanel,rightPanel;

public CalendarPad(int year,int month,int day) {

leftPanel=new JPanel();

JPanel leftCenter=new JPanel(); JPanel leftNorth=new JPanel();

leftCenter.setLayout(new GridLayout(7,7));

rightPanel=new JPanel(); this.year=year; this.month=month; this.day=day;

负责改变年=new Year(this); 负责改变年.setYear(year); 负责改变月=new Month(this); 负责改变月.setMonth(month);

title=new JLabel[7]; showDay=new JTextField[42]; for(int j=0;j<7;j++) {

22

软件课程设计设计(论文)用纸

title[j]=new JLabel(); title[j].setText(星期[j]);

title[j].setBorder(BorderFactory.createRaisedBevelBorder()); leftCenter.add(title[j]); }

title[0].setForeground(Color.red); title[6].setForeground(Color.blue);

for(int i=0;i<42;i++) {

showDay[i]=new JTextField();

showDay[i].addMouseListener(this); showDay[i].setEditable(false); leftCenter.add(showDay[i]); }

日历=Calendar.getInstance();

Box box=Box.createHorizontalBox(); box.add(负责改变年); box.add(负责改变月); leftNorth.add(box);

leftPanel.setLayout(new BorderLayout());

leftPanel.add(leftNorth,BorderLayout.NORTH); leftPanel.add(leftCenter,BorderLayout.CENTER);

leftPanel.add(new Label(\请在年份输入框输入所查年份(负数表示公元前),并回车确定\

BorderLayout.SOUTH) ; leftPanel.validate();

Container con=getContentPane();

JSplitPane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,rightPanel);

con.add(split,BorderLayout.CENTER); con.validate();

hashtable=new Hashtable(); file=new File(\日历记事本.txt\ if(!file.exists()) { try{

FileOutputStream out=new FileOutputStream(file);

ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(hashtable); objectOut.close(); out.close(); }

catch(IOException e)

23

软件课程设计设计(论文)用纸

{ } }

notepad=new NotePad(this); rightPanel.add(notepad);

设置日历牌(year,month);

addWindowListener(new WindowAdapter()

{ public void windowClosing(WindowEvent e) {

System.exit(0); } }); setVisible(true);

setBounds(100,50,524,285); validate(); }

public void 设置日历牌(int year,int month) {

日历.set(year,month-1,1);

星期几=日历.get(Calendar.DAY_OF_WEEK)-1;

if(month==1||month==2||month==3||month==5||month==7 ||month==8||month==10||month==12) { 排列号码(星期几,31); }

else if(month==4||month==6||month==9||month==11) { 排列号码(星期几,30); }

else if(month==2)

{ if((year%4==0&&year0!=0)||(year@0==0)) { 排列号码(星期几,29); } else

{ 排列号码(星期几,28); } } }

public void 排列号码(int 星期几,int 月天数) {

for(int i=星期几,n=1;i<星期几+月天数;i++) { showDay[i].setText(\ if(n==day)

{ showDay[i].setForeground(Color.green); showDay[i].setFont(new Font(\

24