您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 日历记事本完整程序代码
日历记事本完整小程序学校:河南科技学院编写人员:王春山陈敬高时间:2015-12-30packagenet.cw.edu;importjava.util.Calendar;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.io.*;importjava.util.Hashtable;publicclassCalendarPadextendsJFrameimplementsMouseListener{intyear,month,day;Hashtablehashtable;Filefile;JTextFieldshowDay[];//JTextField()创建文本框JLabeltitle[];//JLabel用于短文本字符串或图像或二者的显示区Calendarca;//日历:caintweek;//星期几:weekNotePadnotepad=null;Monthrm;//负责改变月:rmYearry;//负责改变年:ryStringw[]={星期日,星期一,星期二,星期三,星期四,星期五,星期六};//声明两个面板对象JPanelleftPanel,rightPanel;privateintuserid;publicCalendarPad(intyear,intmonth,intday,intuserid){//创建一个标题为日历记事本的窗口super(日历记事本);this.userid=userid;//实例化面板对象leftPanel=newJPanel();//JPanel()为中间容器即面板JPanelleftCenter=newJPanel();JPanelleftNorth=newJPanel();//设置面板布局leftCenter.setLayout(newGridLayout(7,7));//实例化面板对象rightPanel=newJPanel();JPanelrightCenter=newJPanel();JPanelrightSuoth=newJPanel();this.year=year;this.month=month;this.day=day;ry=newYear(this);ry.setYear(year);rm=newMonth(this);rm.setMonth(month);title=newJLabel[7];//设置显示星期区showDay=newJTextField[42];//JTextField()创建文本框//星期区填充for(intj=0;j7;j++){title[j]=newJLabel();title[j].setText(w[j]);title[j].setBorder(BorderFactory.createRaisedBevelBorder());leftCenter.add(title[j]);}title[0].setBackground(Color.green);title[6].setBackground(Color.green);title[0].setForeground(Color.red);title[6].setForeground(Color.blue);//日期区填充for(inti=0;i42;i++){showDay[i]=newJTextField();showDay[i].addMouseListener(this);showDay[i].setEditable(false);leftCenter.add(showDay[i]);}ca=Calendar.getInstance();//使用默认时区和语言环境获得一个日历。Boxbox=Box.createHorizontalBox();//创建一个从左到右显示其组件的Box。box.add(ry);box.add(rm);leftNorth.add(box);leftPanel.setLayout(newBorderLayout());leftPanel.add(leftNorth,BorderLayout.NORTH);leftPanel.add(leftCenter,BorderLayout.CENTER);leftPanel.add(newLabel(请在年份输入框输入所查年份(负数表示公元前),并回车确定),BorderLayout.SOUTH);leftPanel.validate();Containercon=getContentPane();JSplitPanesplit=newJSplitPane(JSplitPane.HORIZONTAL_SPLIT,leftPanel,rightPanel);con.add(split,BorderLayout.CENTER);con.validate();hashtable=newHashtable();file=newFile(日历记事本.txt);if(!file.exists()){try{FileOutputStreamout=newFileOutputStream(file);ObjectOutputStreamobjectOut=newObjectOutputStream(out);objectOut.writeObject(hashtable);objectOut.close();out.close();}catch(IOExceptione){}}notepad=newNotePad(this);Iconicon=newImageIcon(a.gif);JLabellabel=newJLabel(icon,JLabel.CENTER);rightPanel.add(notepad,BorderLayout.CENTER);rightPanel.add(label,BorderLayout.SOUTH);scp(year,month);//设置日历牌:scpaddWindowListener(newWindowAdapter(){publicvoidwindowClosing(WindowEvente){System.exit(0);}});setVisible(true);setBounds(200,100,524,585);validate();}publicintgetUserid(){returnuserid;}publicvoidsetUserid(intuserid){this.userid=userid;}publicvoidscp(intyear,intmonth){ca.set(year,month-1,1);week=ca.get(Calendar.DAY_OF_WEEK)-1;if(month==1||month==3||month==5||month==7||month==8||month==10||month==12){orderNumber(week,31);}elseif(month==4||month==6||month==9||month==11){orderNumber(week,30);}elseif(month==2){if((year%4==0&&year%100!=0)||(year%400==0)){orderNumber(week,29);}else{orderNumber(week,28);}}}publicvoidorderNumber(intwhatDay,intwhatMonth)//排列号码:orderNumber{for(inti=whatDay,n=1;iwhatDay+whatMonth;i++)//星期几:whatDay,月天数:whatMonth{showDay[i].setText(+n);if(n==day){showDay[i].setForeground(Color.pink);//showDay[i].setBackground(Color.pink);showDay[i].setFont(newFont(TimesRoman,Font.BOLD,38));}else{showDay[i].setFont(newFont(TimesRoman,Font.BOLD,20));showDay[i].setForeground(Color.black);//showDay[i].setBackground(C);}if(i%7==6){showDay[i].setForeground(Color.blue);}if(i%7==0){showDay[i].setForeground(Color.red);}n++;}for(inti=0;iwhatDay;i++){showDay[i].setText();}for(inti=whatDay+whatMonth;i42;i++){showDay[i].setText();}}publicintgetYear(){returnyear;}publicvoidsetYear(inty){year=y;notepad.setYear(year);}publicintgetMonth(){returnmonth;}publicvoidsetMonth(intm){month=m;notepad.setMonth(month);}publicintgetDay(){returnday;}publicvoidsetDay(intd){day=d;notepad.setDay(day);}publicHashtablegetHashtable(){returnhashtable;}publicFilegetFile(){returnfile;}publicvoidmousePressed(MouseEvente){JTextFieldsource=(JTextField)e.getSource();try{day=Integer.parseInt(source.getText());notepad.setDay(day);notepad.setInformation(year,month,day);notepad.setArea(null);notepad.getLcontent(year,month,day);}catch(Exceptionee){}}publicvoidmouseClicked(MouseEvente){}publicvoidmouseReleased(MouseEvente){}publicvoidmouseEntered(MouseEvente){}publicvoidmouseExited(MouseEvente){}}packagenet.cw.edu;importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publicclassMonthextendsBoximplementsActionListener{intmonth;JTextFieldshowMonth=null;JButtonnextMonth,lastMonth;//上月:lastMonth,下月:nextMonthCalendarPadcalender;//publicMonth(CalendarPadcalender){super(BoxLayout.X_AXIS);this.calender=calender;showMonth=newJTextField(2);month=calender.getMonth();showMonth.setEditable(false);showMonth.setForeground(Color.blue);showMonth.setFont(newFont(TimesRomn,Font.BO
本文标题:日历记事本完整程序代码
链接地址:https://www.777doc.com/doc-2309314 .html