日历记事本Word文件下载.docx
- 文档编号:18753707
- 上传时间:2023-01-01
- 格式:DOCX
- 页数:40
- 大小:302.13KB
日历记事本Word文件下载.docx
《日历记事本Word文件下载.docx》由会员分享,可在线阅读,更多相关《日历记事本Word文件下载.docx(40页珍藏版)》请在冰豆网上搜索。
getDay(){…………}
setDay(intd){…………}
getHashtable(){…………}
getFile(){…………}
mousePressed(MouseEvente){…………}
main(Stringargs[]){…………}
MonthextendsBoximplementsActionListener类
Month(CalendarPadcalendar){…………}
setMonth(intmonth){…………}
intgetMonth(){…………}
actionPerformed(ActionEvente){…………}
NotePadextendsJPanelimplementsActionListener类
NotePad(CalendarPadcalendar){…………}
setYear(intyear){…………}
setDay(intday){…………}
setNoteContent(intyear,intmonth,intday){…………}
getNoteContent(intyear,intmonth,intday){…………}
saveNote(intyear,intmonth,intday){…………}
delNote(intyear,intmonth,intday){…………}
YearextendsBoximplementsActionListener类
Year(CalendarPadcalendar){…………}
classCalculatorDemoextendsJFrame类
publicCalculatorDemo(){…………}
publicstaticvoidmain(Stringargs[]){…………}
classButtonListenerimplementsActionListener{…………}
四、类结构关系框架图及程序部分截图:
五、程序代码:
importjava.util.Calendar;
importjavax.swing.*;
importjava.awt.*;
importjava.awt.event.*;
importjava.io.*;
importjava.util.Hashtable;
importjava.util.*;
publicclassCalendarPadextendsJFrameimplementsMouseListener
{
intyear,month,day;
Hashtablehashtable;
Filefile;
JTextFieldshowDay[];
JLabeltitle[];
Calendarcalendar;
intweeknum;
NotePadnotepad=null;
MonthvarMonth;
YearvarYear;
Stringweek[]={"
Sunday"
"
Monday"
Tuesday"
Wednesday"
Thursday"
Friday"
Saturday"
};
JPanelleftPanel,rightPanel;
JFramejf;
publicstaticIconicon;
publicstaticImageIconimageIcon;
publicstaticJLabellabelimg;
publicstaticMenuBarmb;
publicstaticMenumFile,mHelp;
publicstaticMenuItemmExit,mAbout;
publicCalendarPad(intyear,intmonth,intday)
{
super("
我的日历记事本"
);
mb=newMenuBar();
mFile=newMenu("
File"
mExit=newMenuItem("
Calendar"
mHelp=newMenu("
Help"
mAbout=newMenuItem("
About"
mFile.add(mExit);
mHelp.add(mAbout);
setMenuBar(mb);
mb.add(mFile);
mb.setHelpMenu(mHelp);
MListenerml=newMListener();
mExit.addActionListener(ml);
mAbout.addActionListener(ml);
leftPanel=newJPanel();
JPanelleftCenter=newJPanel();
JPanelleftNorth=newJPanel();
leftCenter.setLayout(newGridLayout(7,7));
rightPanel=newJPanel();
this.year=year;
this.month=month;
this.day=day;
varYear=newYear(this);
varYear.setYear(year);
varMonth=newMonth(this);
varMonth.setMonth(month);
title=newJLabel[7];
showDay=newJTextField[42];
for(intj=0;
j<
7;
j++)
{
title[j]=newJLabel();
title[j].setText(week[j]);
title[j].setHorizontalAlignment(JLabel.CENTER);
title[j].setBorder(BorderFactory.createRaisedBevelBorder());
leftCenter.add(title[j]);
}
title[0].setForeground(Color.red);
title[6].setForeground(Color.blue);
for(inti=0;
i<
42;
i++)
showDay[i]=newJTextField();
showDay[i].setHorizontalAlignment(JTextField.CENTER);
showDay[i].addMouseListener(this);
showDay[i].setEditable(false);
leftCenter.add(showDay[i]);
}
calendar=Calendar.getInstance();
Boxbox=Box.createHorizontalBox();
box.add(varYear);
box.add(varMonth);
leftNorth.add(box);
leftPanel.setLayout(newBorderLayout());
leftPanel.add(leftNorth,BorderLayout.NORTH);
leftPanel.add(leftCenter,BorderLayout.CENTER);
imageIcon=newImageIcon("
3.jpg"
labelimg=newJLabel();
labelimg.setIcon(imageIcon);
JPanelp1=newJPanel();
p1.setLayout(newBorderLayout());
JPanelp2=newJPanel();
p2.setLayout(newBorderLayout());
JPanelp3=newJPanel();
p3.setLayout(newBorderLayout());
JLabeljLabelFont=newJLabel("
请在年份输入框输入所查年份(负数表示公元前),并回车确定"
jLabelFont.setFont(newFont("
TimesRoman"
Font.BOLD,18));
p3.add(jLabelFont,BorderLayout.WEST);
p3.add(labelimg,BorderLayout.EAST);
leftPanel.add(p3,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);
rightPanel.add(notepad);
setCalender(year,month);
addWindowListener(newWindowAdapter()
{publicvoidwindowClosing(WindowEvente)
System.exit(0);
});
setVisible(true);
setBounds(100,50,784,305);
setResizable(false);
validate();
publicstaticvoidsetJavaLookAndFeel(){
try{
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exceptione){
System.out.println("
设置错误"
}
}
publicvoidsetCalender(intyear,intmonth)
calendar.set(year,month-1,1);
weeknum=calendar.get(Calendar.DAY_OF_WEEK)-1;
if(month==1||month==3||month==5||month==7
||month==8||month==10||month==12)
arrangenum(weeknum,31);
elseif(month==4||month==6||month==9||month==11)
arrangenum(weeknum,30);
elseif(month==2)
if((year%4==0&
&
year%100!
=0)||(year%400==0))
arrangenum(weeknum,29);
else
arrangenum(weeknum,28);
publicvoidarrangenum(intweeknum,intmonthnum)
Calendarcal=Calendar.getInstance();
System.out.println(String.valueOf(cal.get(Calendar.YEAR))+"
-"
+String.valueOf(cal.get(Calendar.MONTH)+1)+"
+String.valueOf(cal.get(Calendar.DAY_OF_MONTH)));
System.out.println("
Day1//"
Day2//"
+String.valueOf(day));
//System.out.println("
monthnum//"
+monthnum);
for(inti=weeknum,n=1;
weeknum+monthnum;
i++)
showDay[i].setText("
"
+n);
//System.out.println("
n//"
if(n==day)
{if(String.valueOf(cal.get(Calendar.DAY_OF_MONTH)).equals(String.valueOf(day))&
String.valueOf(cal.get(Calendar.MONTH)+1).equals(String.valueOf(month))&
String.valueOf(year).equals(String.valueOf(cal.get(Calendar.YEAR))))
{
showDay[i].setForeground(Color.green);
showDay[i].setFont(newFont("
Font.BOLD,20));
Font.BOLD,12));
showDay[i].setForeground(Color.black);
if(i%7==6)
showDay[i].setForeground(Color.blue);
if(i%7==0)
showDay[i].setForeground(Color.red);
n++;
weeknum;
for(inti=weeknum+monthnum;
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();
day=Integer.parseInt(source.getText());
notepad.setNoteContent(year,month,day);
notepad.setTextArea(null);
notepad.getNoteContent(year,month,day);
catch(Exceptionee)
publicvoidmouseClicked(MouseEvente)
publicvoidmouseReleased(MouseEvente)
publicvoidmouseEntered(MouseEvente)
publicvoidmouseExited(MouseEvente)
publicstaticvoidmain(Stringargs[])
Calendarcalendar=Calendar.getInstance();
inty=calendar.get(Calendar.YEAR);
intm=calendar.get(Calendar.MONTH)+1;
intd=calendar.get(Calendar.DAY_OF_MONTH);
newCalendarPad(y,m,d);
}
classMListenerimplementsActionListener{
publicvoidactionPerformed(ActionEvente){
MenuItemi=(MenuItem)e.getSource();
if(i.equals(CalendarPad.mAbout)){
JOptionPane.showMessageDialog(null,"
日历记事本程序V1.0"
关于..."
JOptionPane.INFORMATION_MESSAGE);
elseif(i.equals(CalendarPad.mExit)){
CalculatorDemocd=newCalculatorDemo();
cd.setSize(420,350);
cd.setVisible(true);
}
}}
publicclassMonthextendsBoximplementsActionListener
intmonth;
JTextFieldshowMonth=null;
JButtondownMonth,upMonth;
CalendarPadcalendar;
publicMonth(CalendarPadcalendar)
super(BoxLayout.X_AXIS);
this.calendar=calendar;
showMonth=newJTextField
(2);
month=calendar.getMonth();
showMonth.setEditable(false);
showMonth.setForeground(Color.blue);
showMonth.setFont(newFont("
TimesRomn"
Font.BOLD,16));
downMonth=newJButton("
下月"
upMonth=newJButton("
上月"
add(upMonth);
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 日历 记事本
