![用Java實現(xiàn)日歷記事本源代碼_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/11/b43716d3-7ee9-4400-abd0-22f747ac98ae/b43716d3-7ee9-4400-abd0-22f747ac98ae1.gif)
![用Java實現(xiàn)日歷記事本源代碼_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/11/b43716d3-7ee9-4400-abd0-22f747ac98ae/b43716d3-7ee9-4400-abd0-22f747ac98ae2.gif)
![用Java實現(xiàn)日歷記事本源代碼_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/11/b43716d3-7ee9-4400-abd0-22f747ac98ae/b43716d3-7ee9-4400-abd0-22f747ac98ae3.gif)
![用Java實現(xiàn)日歷記事本源代碼_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/11/b43716d3-7ee9-4400-abd0-22f747ac98ae/b43716d3-7ee9-4400-abd0-22f747ac98ae4.gif)
![用Java實現(xiàn)日歷記事本源代碼_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/11/b43716d3-7ee9-4400-abd0-22f747ac98ae/b43716d3-7ee9-4400-abd0-22f747ac98ae5.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
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("請在年份輸入框輸入所查年份(負數(shù)表示公元前),并回車確定"), 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 月天數(shù)) for(int i=星期幾,n=1;i<星期
10、幾+月天數(shù);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=星期幾+月天數(shù);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.設置文本區(qū)(null); notepad.獲取日志內(nèi)容(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 設置文本區(qū)(String s) text.setText(s); public void 獲取日志內(nèi)容(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 日志內(nèi)容=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,日志內(nèi)容); 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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年度工程項目施工圖設計與審查服務協(xié)議
- 2025年度國際貿(mào)易仲裁條款專用銷售合同
- 2025年橡膠棍項目可行性研究報告
- 職工困難申請書
- 2025年度建筑工程施工勞務人員勞動合同變更合同
- 中國皮卡行業(yè)市場前景預測及投資方向研究報告
- 測井設備項目可行性報告范文參考
- 公共建筑節(jié)能評估報告編制的指南2025-圖文
- 2025年度城市基礎設施建設項目造價咨詢與監(jiān)理服務合同范本
- 2025年電熱無件項目投資可行性研究分析報告
- NB-T 10609-2021 水電工程攔漂排設計規(guī)范
- 藝術(shù)課程標準(2022年版)
- 衛(wèi)生部手術(shù)分級目錄(2023年1月份修訂)
- 2023機械工程師考試試題及答案
- 精選裝飾工程室內(nèi)拆除專項施工方案
- 2022年二年級生命安全教育教案
- 豐田汽車戰(zhàn)略規(guī)劃與戰(zhàn)略管理體系研究(2021)
- 即興口語(姜燕)-課件-即興口語第一章PPT-中國傳媒大學
- 公共政策學(第三版)-課件
- 文物保護項目可行性研究報告
- 冷卻塔是利用水和空氣的接觸
評論
0/150
提交評論