java万年历拓展成日志记事本Word格式.docx
- 文档编号:20470992
- 上传时间:2023-01-23
- 格式:DOCX
- 页数:18
- 大小:17.49KB
java万年历拓展成日志记事本Word格式.docx
《java万年历拓展成日志记事本Word格式.docx》由会员分享,可在线阅读,更多相关《java万年历拓展成日志记事本Word格式.docx(18页珍藏版)》请在冰豆网上搜索。
add(Lmonth);
add(showMonth);
add(Nmonth);
Lmonth.addActionListener(this);
Nmonth.addActionListener(this);
showMonth.setText("
"
+month);
}
publicvoidsetMonth(intmonth)
if(month<
=12&
&
month>
=1)
this.month=month;
else
this.month=1;
publicintgetMonth()
returnmonth;
}
publicvoidactionPerformed(ActionEvente)
if(e.getSource()==Lmonth)
if(month>
=2)
month=month-1;
calendar.setMonth(month);
calendar.setcalendar(calendar.getYear(),month);
elseif(month==1)
month=12;
elseif(e.getSource()==Nmonth)
12)
month=month+1;
elseif(month==12)
month=1;
classYearextendsBoximplementsActionListener//控制年份
intyear;
JTextFieldshowYear=null;
JButtonNyear,Lyear;
publicYear(CalendarPadcalendar)
showYear=newJTextField(4);
showYear.setForeground(Color.blue);
showYear.setFont(newFont("
Font.BOLD,14));
year=calendar.getYear();
Nyear=newJButton("
下年"
Lyear=newJButton("
上年"
add(Lyear);
add(showYear);
add(Nyear);
showYear.addActionListener(this);
Lyear.addActionListener(this);
Nyear.addActionListener(this);
publicvoidsetYear(intyear)
this.year=year;
showYear.setText("
+year);
publicintgetYear()
returnyear;
if(e.getSource()==Lyear)
year=year-1;
calendar.setYear(year);
calendar.setcalendar(year,calendar.getMonth());
elseif(e.getSource()==Nyear)
year=year+1;
elseif(e.getSource()==showYear)
try
year=Integer.parseInt(showYear.getText());
catch(NumberFormatExceptionee)
classNotePadextendsJPanelimplementsActionListener//控制记事
JTextAreatext;
JButtonsavemessage,delmessage;
Hashtabletable;
JLabelmessagebar;
intyear,month,day;
Filefile;
publicNotePad(CalendarPadcalendar)
day=calendar.getDay();
;
table=calendar.getHashtable();
file=calendar.getFile();
messagebar=newJLabel("
+year+"
年"
+month+"
月"
+day+"
日"
JLabel.CENTER);
messagebar.setFont(newFont("
TimesRoman"
messagebar.setForeground(Color.blue);
text=newJTextArea(10,10);
savemessage=newJButton("
保存日志"
);
delmessage=newJButton("
删除日志"
savemessage.addActionListener(this);
delmessage.addActionListener(this);
setLayout(newBorderLayout());
JPanelpSouth=newJPanel();
add(messagebar,BorderLayout.NORTH);
pSouth.add(savemessage);
pSouth.add(delmessage);
add(pSouth,BorderLayout.SOUTH);
add(newJScrollPane(text),BorderLayout.CENTER);
if(e.getSource()==savemessage)
savemessage(year,month,day);
elseif(e.getSource()==delmessage)
delmessage(year,month,day);
publicvoidsetDay(intday)
this.day=day;
publicintgetDay()
returnday;
publicvoidsetmessagebar(intyear,intmonth,intday)
messagebar.setText("
publicvoid设置文本区(Strings)
text.setText(s);
publicvoid获取日志内容(intyear,intmonth,intday)
Stringkey="
+day;
FileInputStreaminOne=newFileInputStream(file);
ObjectInputStreaminTwo=newObjectInputStream(inOne);
table=(Hashtable)inTwo.readObject();
inOne.close();
inTwo.close();
catch(Exceptionee)
if(table.containsKey(key))
Stringm="
这一天有日志记载,想看吗?
intok=JOptionPane.showConfirmDialog(this,m,"
询问"
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if(ok==JOptionPane.YES_OPTION)
text.setText((String)table.get(key));
text.setText("
无记录"
publicvoidsavemessage(intyear,intmonth,intday)
String日志内容=text.getText();
保存日志吗?
table.put(key,日志内容);
FileOutputStreamout=newFileOutputStream(file);
ObjectOutputStreamobjectOut=newObjectOutputStream(out);
objectOut.writeObject(table);
objectOut.close();
out.close();
publicvoiddelmessage(intyear,intmonth,intday)
删除"
日的日志吗?
table.remove(key);
text.setText(null);
无日志记录"
JOptionPane.showMessageDialog(this,m,"
提示"
JOptionPane.WARNING_MESSAGE);
publicclassCalendarPadextendsJFrameimplementsMouseListener//控制主体框架
Hashtablehashtable;
JTextFieldshowDay[];
JLabeltitle[];
Calendarcalendar;
int星期几;
NotePadnotepad=null;
Month负责改变月;
Year负责改变年;
String星期[]={"
星期日"
"
星期一"
星期二"
星期三"
星期四"
星期五"
星期六"
};
JPanelleftPanel,rightPanel;
publicCalendarPad(intyear,intmonth,intday)
super("
日历记事本-byJackbase"
leftPanel=newJPanel();
JPanelleftCenter=newJPanel();
JPanelleftNorth=newJPanel();
leftCenter.setLayout(newGridLayout(7,7));
rightPanel=newJPanel();
负责改变年=newYear(this);
负责改变年.setYear(year);
负责改变月=newMonth(this);
负责改变月.setMonth(month);
title=newJLabel[7];
showDay=newJTextField[42];
for(intj=0;
j<
7;
j++)
title[j]=newJLabel();
title[j].setText(星期[j]);
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=newJTextField();
showDay.addMouseListener(this);
showDay.setEditable(false);
leftCenter.add(showDay);
calendar=Calendar.getInstance();
Boxbox=Box.createHorizontalBox();
box.add(负责改变年);
box.add(负责改变月);
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{
objectOut.writeObject(hashtable);
catch(IOExceptione)
notepad=newNotePad(this);
rightPanel.add(notepad);
setcalendar(year,month);
addWindowListener(newWindowAdapter()
{publicvoidwindowClosing(WindowEvente)
System.exit(0);
});
setVisible(true);
setBounds(100,50,544,285);
validate();
publicvoidsetcalendar(intyear,intmonth)
calendar.set(year,month-1,1);
星期几=calendar.get(Calendar.DAY_OF_WEEK)-1;
if(month==1||month==2||month==3||month==5||month==7
||month==8||month==10||month==12)
排列号码(星期几,31);
elseif(month==4||month==6||month==9||month==11)
排列号码(星期几,30);
elseif(month==2)
if((year%4==0&
year%100!
=0)||(year%400==0))
排列号码(星期几,29);
排列号码(星期几,28);
publicvoid排列号码(int星期几,int月天数)
for(inti=星期几,n=1;
星期几+月天数;
i++)
showDay.setText("
+n);
if(n==day)
showDay.setForeground(Color.green);
showDay.setFont(newFont("
Font.BOLD,20));
Font.BOLD,12));
showDay.setForeground(Color.black);
if(i%7==6)
showDay.setForeground(Color.blue);
if(i%7==0)
showDay.setFor
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- java 万年历 拓展 日志 记事本
![提示](https://static.bdocx.com/images/bang_tan.gif)