




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、CalendarPad类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; Cale
2、ndar 日历; int 星期几; NotePad notepad=null; Month 负责改变月; Year 负责改变年; String 星期="星期日","星期一","星期二","星期三","星期四","星期五","星期六" JPanel leftPanel,rightPanel; public CalendarPad(int year,int month,int day) leftPanel=new JPanel(); JPanel leftCe
3、nter=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 JLabel7; showDay=new JTextField42; f
4、or(int j=0;j<7;j+) titlej=new JLabel(); titlej.setText(星期j); titlej.setBorder(BorderFactory.createRaisedBevelBorder(); leftCenter.add(titlej); title0.setForeground(Color.red); title6.setForeground(Color.blue); for(int i=0;i<42;i+) showDayi=new JTextField(); showDayi.addMouseListener(this); sho
5、wDayi.setEditable(false); leftCenter.add(showDayi); 日历=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); le
6、ftPanel.add(new Label("请在年份输入框输入所查年份(负数表示公元前),并回车确定"), 6 / 25 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 Ha
7、shtable(); 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) notepad=new NotePad(this); rightPan
8、el.add(notepad); 设置日历牌(year,month); 7 / 25 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(m
9、onth=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&&year%100!=0)|(year%400=0) 排列号码(星期几,29); 8 / 25 else 排列号码(星期几,28); public void 排列号码(int 星期几,int 月天数) for(int i=星期几,n=1;i<星期
10、几+月天数;i+) showDayi.setText(""+n); if(n=day) showDayi.setForeground(Color.green); showDayi.setFont(new Font("TimesRoman",Font.BOLD,20); else showDayi.setFont(new Font("TimesRoman",Font.BOLD,12); showDayi.setForeground(Color.black); if(i%7=6) showDayi.setForeground(Color.
11、blue); if(i%7=0) showDayi.setForeground(Color.red); 9 / 25 n+; for(int i=0;i<星期几;i+) showDayi.setText(""); for(int i=星期几+月天数;i<42;i+) showDayi.setText(""); public int getYear() return year; public void setYear(int y) year=y; notepad.setYear(year); public int getMonth() retu
12、rn month; public void setMonth(int m) month=m; notepad.setMonth(month); public int getDay() return day; public void setDay(int d) day=d; notepad.setDay(day); public Hashtable getHashtable() return hashtable; public File getFile() return file; public void mousePressed(MouseEvent e) JTextField source=
13、(JTextField)e.getSource();try day=Integer.parseInt(source.getText(); notepad.setDay(day); notepad.设置信息条(year,month,day); notepad.设置文本区(null); notepad.获取日志内容(year,month,day); catch(Exception ee) public void mouseClicked(MouseEvent e) public void mouseReleased(MouseEvent e) public void mouseEntered(Mo
14、useEvent e) public void mouseExited(MouseEvent e) public static void main(String args) Calendar calendar=Calendar.getInstance(); int y=calendar.get(Calendar.YEAR); int m=calendar.get(Calendar.MONTH)+1; int d=calendar.get(Calendar.DAY_OF_MONTH); new CalendarPad(y,m,d); 2、) Month类import javax.swing.*;
15、import java.awt.*;import java.awt.event.*; 11 / 25 public class Month extends Box implements ActionListener int month; JTextField showMonth=null; JButton 下月,上月; CalendarPad 日历; public Month(CalendarPad 日历) super(BoxLayout.X_AXIS); this.日历=日历; showMonth=new JTextField(2); month=日历.getMonth(); showMon
16、th.setEditable(false); showMonth.setForeground(Color.blue); showMonth.setFont(new Font("TimesRomn",Font.BOLD,16); 下月=new JButton("下月"); 上月=new JButton("上月"); add(上月); add(showMonth); add(下月); 上月.addActionListener(this); 下月.addActionListener(this); showMonth.setText(&quo
17、t;"+month); public void setMonth(int month) if(month<=12&&month>=1) this.month=month; else this.month=1; showMonth.setText(""+month); 12 / 25 public int getMonth() return month; public void actionPerformed(ActionEvent e) if(e.getSource()=上月) if(month>=2) month=month-1
18、; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); else if(month=1) month=12; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); showMonth.setText(""+month); else if(e.getSource()=下月) if(month<12) month=month+1; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); else if(month=12) month=1
19、; 日历.setMonth(month); 日历.设置日历牌(日历.getYear(),month); showMonth.setText(""+month); 13 / 25 3、)NotePad类import java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.event.*;import java.io.*;public class NotePad extends JPanel implements ActionListener JT
20、extArea text; JButton 保存日志,删除日志; Hashtable table; JLabel 信息条; int year,month,day; File file; CalendarPad calendar; public NotePad(CalendarPad calendar) this.calendar=calendar; year=calendar.getYear(); month=calendar.getMonth(); day=calendar.getDay(); table=calendar.getHashtable(); file=calendar.getF
21、ile(); 信息条=new JLabel(""+year+"年"+month+"月"+day+"日",JLabel.CENTER); 信息条.setFont(new Font("TimesRoman",Font.BOLD,16); 信息条.setForeground(Color.blue); text=new JTextArea(10,10); 14 / 25 保存日志=new JButton("保存日志") ; 删除日志=new JButton("删除日志&qu
22、ot;) ; 保存日志.addActionListener(this); 删除日志.addActionListener(this); setLayout(new BorderLayout(); JPanel pSouth=new JPanel(); add(信息条,BorderLayout.NORTH); pSouth.add(保存日志); pSouth.add(删除日志); add(pSouth,BorderLayout.SOUTH); add(new JScrollPane(text),BorderLayout.CENTER); public void actionPerformed(Ac
23、tionEvent e) if(e.getSource()=保存日志) 保存日志(year,month,day); else if(e.getSource()=删除日志) 删除日志(year,month,day); public void setYear(int year) this.year=year; public int getYear() return year; public void setMonth(int month) this.month=month; public int getMonth() return month; public void setDay(int day
24、) this.day=day; public int getDay() return day; public void 设置信息条(int year,int month,int day) 信息条.setText(""+year+"年"+month+"月"+day+"日"); public void 设置文本区(String s) text.setText(s); public void 获取日志内容(int year,int month,int day) String key=""+year+&
25、quot;"+month+""+day; try FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); catch(Exception ee) if(table.containsKey(key) String m=""+year+"年"+mon
26、th+"月"+day+"这一天有日志记载,想看吗?" int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION, 16 / 25 JOptionPane.QUESTION_MESSAGE); if(ok=JOptionPane.YES_OPTION) text.setText(String)table.get(key); else text.setText(""); else text.setText("无记录&q
27、uot;); public void 保存日志(int year,int month,int day) String 日志内容=text.getText(); String key=""+year+""+month+""+day; String m=""+year+"年"+month+"月"+day+"保存日志吗?" int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane
28、.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(ok=JOptionPane.YES_OPTION) try 17 / 25 FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); table.put(key,日志内容); FileOutputStream out
29、=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); catch(Exception ee) public void 删除日志(int year,int month,int day) String key=""+year+""+month+""+day; if(table.containsKey
30、(key) String m="删除"+year+"年"+month+"月"+day+"日的日志吗?" 18 / 25 int ok=JOptionPane.showConfirmDialog(this,m,"询问",JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(ok=JOptionPane.YES_OPTION) try FileInputStream inOne=new FileInputStream(file);
31、ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); table.remove(key); FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); 19 /
32、 25 out.close(); text.setText(null); catch(Exception ee) else String m=""+year+"年"+month+"月"+day+"无日志记录" JOptionPane.showMessageDialog(this,m,"提示",JOptionPane.WARNING_MESSAGE); 4、)Year 类import javax.swing.*;import java.awt.*;import java.awt.event.*;public class Year extends Box implements ActionListener int year; JTextField showYear=null; JButton 明年,去年; CalendarPad 日历; publ
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年中国无菌干手器市场调查研究报告
- 2025年中国方底阀口袋数据监测报告
- 2025至2030年中国弯樁头机市场分析及竞争策略研究报告
- 肇庆市实验中学高中历史三:第五单元检测
- 新疆克拉玛依市白碱滩区2025年小升初数学检测卷含解析
- 2025-2030年中国LNG市场发展规划及需求预测研究报告
- 2025-2030年中国PCB药水市场竞争格局及发展前景预测研究报告
- 邢台学院《药品质量管理工程》2023-2024学年第二学期期末试卷
- 2025至2031年中国碳钢止回阀铸件行业投资前景及策略咨询研究报告
- 2025至2031年中国磷霉素氨丁三醇行业投资前景及策略咨询研究报告
- 2025至2030中国白电市场竞争战略规划与运行态势研究报告
- 烟草证借用合同范本
- 烧烫伤培训课件
- 煤矿重大事故隐患判定标准解读与查找方法山西应急管理厅培训课件
- 工业废水处理工考核要素细目表与考核内容结构表(征求意见稿)
- 有限合伙制私募股权基金整体框架图解及案例
- 2025年中小学教师资格考试题库大全及答案
- 机器人自主导航与定位技术难点测试考核试卷
- T-MSC 005-2024 灵芝孢子油生产加工技术规范
- 《中华人民共和国预算法》知识培训
- TSCBDIF 001-2024 AI 大模型应用能力成熟度评价标准
评论
0/150
提交评论