日历记事本完整程序代码.docx

上传人:b****5 文档编号:7164865 上传时间:2023-01-21 格式:DOCX 页数:35 大小:24.27KB
下载 相关 举报
日历记事本完整程序代码.docx_第1页
第1页 / 共35页
日历记事本完整程序代码.docx_第2页
第2页 / 共35页
日历记事本完整程序代码.docx_第3页
第3页 / 共35页
日历记事本完整程序代码.docx_第4页
第4页 / 共35页
日历记事本完整程序代码.docx_第5页
第5页 / 共35页
点击查看更多>>
下载资源
资源描述

日历记事本完整程序代码.docx

《日历记事本完整程序代码.docx》由会员分享,可在线阅读,更多相关《日历记事本完整程序代码.docx(35页珍藏版)》请在冰豆网上搜索。

日历记事本完整程序代码.docx

日历记事本完整程序代码

日历记事本完整小程序

学校:

河南科技学院

编写人员:

王春山陈敬高

时间:

2015-12-30

packagenet.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;//日历:

ca

intweek;//星期几:

week

NotePadnotepad=null;

Monthrm;//负责改变月:

rm

Yearry;//负责改变年:

ry

Stringw[]={"星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

//声明两个面板对象

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;j<7;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;i<42;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);//设置日历牌:

scp

addWindowListener(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;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;i

{

showDay[i].setText("");

}

for(inti=whatDay+whatMonth;i<42;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,下月:

nextMonth

CalendarPadcalender;//

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.BOLD,16));

nextMonth=newJButton("下月");

lastMonth=newJButton("上月");

add(lastMonth);

add(showMonth);

add(nextMonth);

lastMonth.addActionListener(this);

nextMonth.addActionListener(this);

showMonth.setText(""+month);

}

publicvoidsetMonth(intmonth)

{

if(month<=12&&month>=1)

{

this.month=month;

}

else

{

this.month=1;

}

showMonth.setText(""+month);

}

publicintgetMonth()

{

returnmonth;

}

publicvoidactionPerformed(ActionEvente)

{

if(e.getSource()==lastMonth)

{

if(month>=2)

{

month=month-1;

calender.setMonth(month);

calender.scp(calender.getYear(),month);

}

elseif(month==1)

{

month=12;

calender.ry.setYear(calender.ry.year-1);

calender.setMonth(month);

calender.scp(calender.getYear(),month);

}

showMonth.setText(""+month);

}

elseif(e.getSource()==nextMonth)

{

if(month<12)

{

month=month+1;

calender.setMonth(month);

calender.scp(calender.getYear(),month);

}

elseif(month==12)

{

month=1;

calender.ry.setYear(calender.ry.year+1);

calender.setMonth(month);

calender.scp(calender.getYear(),month);

}

showMonth.setText(""+month);

}

}

}

packagenet.cw.edu;

importjava.awt.BorderLayout;

importjava.awt.Color;

importjava.awt.Font;

importjava.awt.event.ActionEvent;

importjava.awt.event.ActionListener;

importjava.io.File;

importjava.io.UnsupportedEncodingException;

importjava.sql.Connection;

importjava.sql.PreparedStatement;

importjava.sql.ResultSet;

importjava.sql.SQLException;

importjava.util.Hashtable;

importjavax.swing.JButton;

importjavax.swing.JLabel;

importjavax.swing.JOptionPane;

importjavax.swing.JPanel;

importjavax.swing.JScrollPane;

importjavax.swing.JTextArea;

importnet.cw.view.DB;

publicclassNotePadextendsJPanelimplementsActionListener{

JTextAreatext;

JButtonsaveLog,deleteLog;//保存日志,删除日志:

saveLog,deleteLog

Hashtabletable;

JLabelarticleInformation;//信息条:

articleInformation.

intyear,month,day;

Filefile;

CalendarPadcalendar;

publicNotePad(CalendarPadcalendar)

{

this.calendar=calendar;

year=calendar.getYear();

month=calendar.getMonth();

day=calendar.getDay();;

table=calendar.getHashtable();

file=calendar.getFile();

articleInformation=newJLabel(""+year+"年"+month+"月"+day+"日",JLabel.CENTER);

articleInformation.setFont(newFont("TimesRoman",Font.BOLD,16));

articleInformation.setForeground(Color.blue);

text=newJTextArea(10,10);

saveLog=newJButton("保存日志");

deleteLog=newJButton("删除日志");

saveLog.addActionListener(this);

deleteLog.addActionListener(this);

setLayout(newBorderLayout());

JPanelpSouth=newJPanel();

add(articleInformation,BorderLayout.NORTH);

pSouth.add(saveLog);

pSouth.add(deleteLog);

add(pSouth,BorderLayout.SOUTH);

add(newJScrollPane(text),BorderLayout.CENTER);

}

publicvoidactionPerformed(ActionEvente)

{

if(e.getSource()==saveLog)

{

saveLog(year,month,day);

}

elseif(e.getSource()==deleteLog)

{

deleteLog(year,month,day);

}

}

publicvoidsetYear(intyear)

{

this.year=year;

}

publicintgetYear()

{

returnyear;

}

publicvoidsetMonth(intmonth)

{

this.month=month;

}

publicintgetMonth()

{

returnmonth;

}

publicvoidsetDay(intday)

{

this.day=day;

}

publicintgetDay()

{

returnday;

}

publicvoidsetInformation(intyear,intmonth,intday)//设置信息条:

setInformation

{

articleInformation.setText(""+year+"年"+month+"月"+day+"日");

}

publicvoidsetArea(Strings)//设置文本区:

setArea

{

text.setText(s);

}

publicvoidgetLcontent(intyear,intmonth,intday)//获取日志内容:

getLcontent

{

Stringkey=""+year+"年"+month+"月"+day+"日";

Stringtext=searchLogLogic(year,month,day,key);

if(null!

=text){

Stringm=""+year+"年"+month+"月"+day+"这一天有日志记载,想看吗?

";

intok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION,

JOptionPan

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 自然科学 > 化学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1