ImageVerifierCode 换一换
格式:DOCX , 页数:26 ,大小:231.39KB ,
资源ID:16478480      下载积分:5 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bingdoc.com/d-16478480.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(用Java实现日历记事本.docx)为本站会员(b****6)主动上传,冰点文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰点文库(发送邮件至service@bingdoc.com或直接QQ联系客服),我们立即给予删除!

用Java实现日历记事本.docx

1、用Java实现日历记事本用Java实现日历记事本1. 实验目的掌握RandomAccessFile类的使用;掌握字符输入、输出流和缓冲输入、输出流的使用。2. 实验要求 实验前,应事先熟悉相关知识点,拟出相应的实验操作步骤,明确实验目的和要求;实验过程中,服从实验指导教师安排,遵守实验室的各项规章制度,爱护实验仪器设备;实验操作完成后,认真书写实验报告,总结实验经验,分析实验过程中出现的问题。3. 实验内容编程实现日历记事本。具体要求如下:(1)该日历可以通过在文本框中输入年份和月份设置日期,也可按年前后翻动,用鼠标左键单击“上年”和“下年”按钮,将当前日历的年份减一和加一。还可以在某年内按月

2、前后翻动,用鼠标左键单击“上月”和“下月”按钮,将日历的月份减一和加一。(2)左键单击日历上的日期,可以通过右侧的记事本(文本区)编辑有关日志,并将日志保存到一个文件,该文件的名字是由当前日期组成的字符序列。用户可以读取、删除某个日期的日志,也可以继续向某个日志添加新的内容。在保存、删除和读取日志时都会先弹出一个确认对话框,以确认保存、删除和读取操作。(3)当某个日期有日志时,该日期以粗体16号字显示,表明这个日期有日志;当用户删除某个日期的日志后,该日期恢复原来的外观。实现效果图(参考)如下:提示:(1)组件调用public void setFont(Fontf)方法可以设置组件上的字体,F

3、ont类的构造方法为:public Font(Stringname,intstyle,intsize),其中name是字体的名字,style决定字体的样式(如Font.BOLD表示粗体)size决定字体的大小。(具体请参考JDK API)(2)当左键单击日历上的日期时,如要获取该日期,可通过处理该组件上的鼠标事件来实现。4实验步骤、实施过程、关键代码、实验结果及分析说明等1. CalendarPad类(1) 进行整体布局,建立日历记事本文件,设置日历卡,把日期按星期顺序排列,并用窗口监视器实现。(2)用窗口监视器实现,结果如下:2. Notepad类(1) 对日期的设置和获取,设置信息条,对文

4、本框进行设置,保存日志、删除日志和读取日志按钮的事件实现。(2)保存日志按钮事件实现如下:(3)读取日志按钮事件实现如下:(4.)删除日志按钮事件实现如下:3Year类(1)输入年份可以实现输出,给上下年按钮设置监视器,对上下年按钮事件的实现。(2)其结果如下:4. Month类(1)设置上下月监视器,对上下月按钮的事件实现,区分闰年和平年,对天数不同的月份进行分类。(2)其结果如下:(续上页,可加页)5各个类的源代码如下:CalendarPad 类:/CalendarPad.javaimport java.util.Calendar;import javax.swing.*;import j

5、ava.awt.*;import java.awt.event.*;import java.io.*;import java.util.Hashtable;public class CalendarPad extends JFrame implements MouseListener,ActionListener int year,month,day; Hashtable hashtable; JButton Save,Delete,Read; File file; JTextField showDay; JLabel title; Calendar Date; int Weekday; No

6、tePad notepad=null; Month ChangeMonth; Year ChangeYear ; String week=星期日,星期一,星期二,星期三,星期四,星期五,星期六; JPanel leftPanel,rightPanel; public CalendarPad(int year,int month,int day) leftPanel=new JPanel(); JPanel leftCenter=new JPanel(); JPanel leftNorth=new JPanel(); leftCenter.setLayout(new GridLayout(7,7

7、); rightPanel=new JPanel(); this.year=year; this.month=month; this.day=day; ChangeYear=new Year(this); ChangeYear.setYear(year); ChangeMonth=new Month(this); ChangeMonth.setMonth(month); title=new JLabel7; showDay=new JTextField42; for(int j=0;j7;j+) titlej=new JLabel(); titlej.setText(weekj); title

8、j.setBorder(BorderFactory.createRaisedBevelBorder(); titlej.setForeground(Color.blue); leftCenter.add(titlej); for(int i=0;i42;i+) showDayi=new JTextField(); showDayi.addMouseListener(this); showDayi.setEditable(false); leftCenter.add(showDayi); Save=new JButton(保存日志) ; Delete=new JButton(删除日志) ; Re

9、ad=new JButton(读取日志) ; Read.addActionListener(this); Save.addActionListener(this); Delete.addActionListener(this); /设置监视器 JPanel pSouth=new JPanel(); pSouth.add(Save); pSouth.add(Delete); pSouth.add(Read); Date=Calendar.getInstance(); Box box=Box.createHorizontalBox(); box.add(ChangeYear); box.add(C

10、hangeMonth); leftNorth.add(box); leftPanel.setLayout(new BorderLayout(); add(leftNorth,BorderLayout.NORTH); leftPanel.add(leftCenter,BorderLayout.CENTER); add(pSouth,BorderLayout.SOUTH); leftPanel.validate(); notepad=new NotePad(this); rightPanel.add(notepad); Container con=getContentPane(); JSplitP

11、ane split=new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, leftPanel,rightPanel); con.add(split,BorderLayout.CENTER); /进行整体布局 con.validate(); hashtable=new Hashtable(); file=new File(日历记事本.txt); if(!file.exists() try FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new Object

12、OutputStream(out); objectOut.writeObject(hashtable); objectOut.close(); out.close(); catch(IOException e) setCalendar(year,month); addWindowListener(new WindowAdapter() /设置窗口监视器 public void windowClosing(WindowEvent e) System.exit(0); ); setVisible(true); setBounds(100,60,524,335); validate(); publi

13、c void actionPerformed(ActionEvent e) if(e.getSource()=Save) notepad.Save(file,year,month,day); else if(e.getSource()=Delete) notepad.Delete(file,year,month,day); else if(e.getSource()=Read) notepad.Read(file,year,month,day); public void setCalendar(int year,int month) /设置日历卡 Date.set(year,month-1,1

14、); Weekday=Date.get(Calendar.DAY_OF_WEEK)-1; if(month=1|month=2|month=3|month=5|month=7 |month=8|month=10|month=12) Arrange(Weekday,31); else if(month=4|month=6|month=9|month=11) Arrange(Weekday,30); else if(month=2) if(year%4=0&year%100!=0)|(year%400=0) Arrange(Weekday,29); else Arrange(Weekday,28)

15、; public void Arrange(int Weekday,int Monthday) /把日期,按星期排列 for(int i=Weekday,n=1;iWeekday+Monthday;i+) showDayi.setText(+n); if(n=day) showDayi.setForeground(Color.blue); showDayi.setFont(new Font(TimesRoman,Font.BOLD,20); else showDayi.setFont(new Font(TimesRoman,Font.BOLD,12); showDayi.setForegrou

16、nd(Color.black); n+; for(int i=0;iWeekday;i+) showDayi.setText(); for(int i=Weekday+Monthday;i42;i+) showDayi.setText(); public int getYear() return year; public void setYear(int y) year=y; notepad.setYear(year); public int getMonth() return month; public void setMonth(int m) month=m; notepad.setMon

17、th(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=(JTextField)e.getSource();try day=Integer.parseInt(source.get

18、Text(); notepad.setDay(day); notepad.setNews(year,month,day); notepad.setText(null); catch(Exception ee) public void mouseClicked(MouseEvent e)public void mouseReleased(MouseEvent e)public void mouseExited(MouseEvent e)public void mouseEntered(MouseEvent e)public static void main(String args) Calend

19、ar 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); NotePad类/ NotePad.javaimport java.awt.*;import java.awt.event.*;import java.util.*;import javax.swing.*;import javax.swing.e

20、vent.*;import java.io.*;public class NotePad extends JPanel implements ActionListener JTextArea text; Hashtable table; JLabel News; int year,month,day; File file; CalendarPad calendar; public NotePad(CalendarPad calendar) this.calendar=calendar; year=calendar.getYear(); month=calendar.getMonth(); da

21、y=calendar.getDay(); table=calendar.getHashtable(); file=calendar.getFile(); News=new JLabel(+year+年+month+月+day+日,JLabel.CENTER); News.setFont(new Font(TimesRoman,Font.BOLD,20); text=new JTextArea(10,15); setLayout(new BorderLayout(); JPanel pSouth=new JPanel(); add(News,BorderLayout.NORTH); add(pS

22、outh,BorderLayout.SOUTH); add(new JScrollPane(text),BorderLayout.CENTER); 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) this.day=day; public int getDay(

23、) return day; public void setNews(int year,int month,int day) News.setText(+year+年+month+月+day+日); public void setText(String s) text.setText(s); public void actionPerformed(ActionEvent e) public void Save(File file,int year,int month,int day) /保存日志按钮事件实现 String LogCenter=text.getText(); String key=

24、+year+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+年+month+月+day+已存在日志,是否更新?; /是更新已有的日志 int ok=JOpt

25、ionPane.showConfirmDialog(this,m,询问,JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(ok=JOptionPane.YES_OPTION) try FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputStream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); ta

26、ble.remove(key); FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); text.setText(null); catch(Exception ee) String f=日志已更新; JOptionPane.showMessageDialog(this,f,提示,JOptionPane.WARNIN

27、G_MESSAGE); else String m=+year+年+month+月+day+还没有日志,是否保存日志?; /保存还没有的日志 int ok=JOptionPane.showConfirmDialog(this,m,询问,JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if(ok=JOptionPane.YES_OPTION) try FileInputStream inOne=new FileInputStream(file); ObjectInputStream inTwo=new ObjectInputSt

28、ream(inOne); table=(Hashtable)inTwo.readObject(); inOne.close(); inTwo.close(); table.put(key,LogCenter); FileOutputStream out=new FileOutputStream(file); ObjectOutputStream objectOut=new ObjectOutputStream(out); objectOut.writeObject(table); objectOut.close(); out.close(); catch(Exception ee) Strin

29、g f=日志保存成功; JOptionPane.showMessageDialog(this,f,提示,JOptionPane.WARNING_MESSAGE); public void Delete(File file,int year,int month,int day) /删除日志按钮事件实现 String key=+year+month+day; if(table.containsKey(key) String m=删除+year+年+month+月+day+日的日志吗?; int yes=JOptionPane.showConfirmDialog(this,m,询问,JOptionPane.YES_NO_OPTION, JOptionPane.QU

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2