版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
PAGEPAGE3JIANGXIAGRICULTURALUNIVERSITYJAVA课程设计报告题目:《写字留痕》课程设计学院:******姓名:***学号:********专业:软件工程班级:软件1****班指导教师:**职称:****二0一二年月摘要学习一门语言,重要的是表达。课程设计就是这样一次表达的机会。“表达”,即程序设计。Java是一种可以撰写跨平台应用软件的面向对象的程序设计语言。在全球云计算和移动互联网的产业环境下,Java更具备了显著优势和广阔前景。随着家庭电脑的普及,拥有一个体积小巧、使用方便、功能强大的记事本来记录每一天的点点滴滴,已经变得越来越重要。Windows自带的记事本使用很方便,但是功能不够强大,所以要开发一款更加强大的软件来满足市场需求。关键词:记事本。
目录
设计需求基本设计要求:日记本使用Java语言开发设计。课程的基本功能包括万年历、记事本和辅助功能三个部分。万年历部分由微调器确定年月,由一组文本框显示日历。年月可选择数据符合逻辑,默认为当前日期。月历显示应该符合查看习惯,如星期六和星期日分别用不同颜色表示,当日可用特别的字号和颜色及时本区,记事本内容按年月日记录且保存。微调器应该进行事件设置,以及即时地显示该年月的月历;日期文本框可监听鼠标事件,当单击任何一个日期时,若该日有记事内容,则在日记本中显示该日期的记录文字;若该日无记录,记事区保持空白。日记本应该是开放的,内容可按日期增减,保存应即时,删除需谨慎删除记录时,应进行对话框询问确定。辅助功能包含了日记的导入导出。“导入”可以将其他日记文件导入合并到当前“写字留痕”的日记本中;“导出”可将“写字留痕”的所有记录内容按日期为序导出到一个文本文件中。系统界面外观和布局,可个性化设计,总体原则是“界面简洁,操作便捷”。
2系统设计 本系统采用java语言开发,开发工具为记事本,运行环境为JDK1.6。2.2总体设计结构图 主框架万年历记事本选择微调按钮 输入保存删除导入导出 2.3万年历模块流程图 万年历 选择微调按钮 选择日期 正确输入 错误输入 改变当天日期 当天是否有日记? 有 无 更改记事本显示 2.4日记本模块流程图 显示日记本 保存 删除 导入 导出以当前日期为值,如果当前TreeMap 打开打开文件对打开保存文件当前内容为值保有今天的记录就 话框,如果选择对话框,保存存到TreeMap中删除它 了文件就导入 到所选路径下2.5主视窗界面主界面:保存界面删除界面:导入文件:导出文件:源代码:importjavax.swing.*;importjava.awt.*;importjava.io.*;importjava.awt.event.*;importjava.util.*;importjavax.swing.event.*;importjava.text.*;importjava.lang.*;importjavax.swing.border.*;classSexBoxextendsJPanel//设置选取天气的面板{JComboBoxc; JComboBoxcb; SexBox() { super(newFlowLayout()); c=newJComboBox(newString[]{"晴","雨","阴","雪"}); cb=newJComboBox(newString[]{"愉快","悲伤","忧郁","平常"}); add(newJLabel("天气")); add(c); add(newJLabel("心情")); add(cb); }}classAreaDateextendsJPanel//设置万年历放置的文本{intdays; intfirst; JTextAreashowDay[]; DateTimedateTime=newDateTime(1); AreaDate() { super(newGridLayout(6,7,5,5)); showDay=newJTextArea[42]; for(inti=0;i<42;i++) { showDay[i]=newJTextArea(1,1); add(showDay[i]); } arrangeNum(dateTime.year,dateTime.month,dateTime.date); System.out.println(dateTime.year); } AreaDate(inti){} publicvoidarrangeNum(intyear,intmonth,intday) { days=dateTime.getMonday(year,month); Calendarc=Calendar.getInstance(); c.set(year,month-1,1); first=c.get(Calendar.DAY_OF_WEEK)-1; for(inti=first,n=1;i<first+days;i++,n++) { showDay[i].setText(""+n); showDay[i].setBackground(newColor(238,238,238)); if(n==c.get(c.DATE)) { showDay[i].setForeground(Color.green); showDay[i].setFont(newFont("TimesRoman",Font.BOLD,20)); } elseif(n==day) { showDay[i].setFont(newFont("TimesRoman",Font.BOLD,20)); showDay[i].setForeground(Color.white); showDay[i].setBackground(Color.GRAY); } elseif(i%7==0||i%7==6) { showDay[i].setForeground(Color.red); showDay[i].setFont(newFont("TimesRoman",Font.BOLD,20)); } else { showDay[i].setFont(newFont("TimesRoman",Font.BOLD,20)); showDay[i].setForeground(Color.black); } } for(inti=0;i<42;i++) { if(i<first||i>=first+days) { showDay[i].setBackground(newColor(238,238,238)); showDay[i].setText(""); } } }}classWeekextendsJPanel//设置星期{ JLabellab[]; //JLabellabPic; Stringstr[]={"日","一","二","三","四","五","六"}; Week() { super(newGridLayout(1,7,5,5)); init(); } publicvoidinit() { lab=newJLabel[7]; //labPic=newJLabel(newImageIcon("logo[1].png")); //add(labPic); for(inti=0;i<7;i++) { lab[i]=newJLabel(str[i]); //lab[i].setFont(newFont("楷体",Font.BOLD,20)); add(lab[i]); } }}classYearMonthextendsJPanel//设置选取时间的面板{intyear; intmonth; intdate; JLabely1,m1,d1; JSpinnershowYear,showMonth,showDate; SpinnerNumberModelyearModel,monthModel,dateModel; DateTimedateTime=newDateTime(1); YearMonth() { ymInit(); add(showYear); add(y1); add(showMonth); add(m1); add(showDate); add(d1); } voidymInit()//选取时间进度条 { y1=newJLabel("年"); m1=newJLabel("月"); d1=newJLabel("日"); //DateTime=Calendar.getInstance(); year=dateTime.getYear(); month=dateTime.getMonth(); date=dateTime.getDate(); //areaDate.arrangeNum(year,month,date); yearModel=newSpinnerNumberModel(year,0,10000,1); showYear=newJSpinner(yearModel); //showYear.addChangeListener(this); showYear.setEditor(newJSpinner.NumberEditor(showYear,"0000")); y1.setFont(newFont("TimesRonmn",Font.BOLD,16)); monthModel=newSpinnerNumberModel(month,1,12,1); showMonth=newJSpinner(monthModel); //showMonth.addChangeListener(this); m1.setFont(newFont("TimesRonmn",Font.BOLD,16)); dateModel=newSpinnerNumberModel(date,1,31,1); showDate=newJSpinner(dateModel); //showDate.addChangeListener(this); d1.setFont(newFont("TimesRonmn",Font.BOLD,16)); }}classDateTime//时间的设置{ publicstaticintyear; publicstaticintmonth; publicstaticintdate; publicCalendarc; DateTime() { c=Calendar.getInstance(); year=c.get(c.YEAR); month=c.get(c.MONTH)+1; date=c.get(c.DATE); } DateTime(inti){} publicintgetYear() { returnyear; } publicintgetMonth() { returnmonth; } publicintgetDate() { returndate; } publicintgetMonday(intyear,intmonth) { if(((year%4==0&&year%100!=0)||year%400==0)&&month==2) { return29; } elseif(month==1||month==3||month==5||month==7||month==8||month==10||month==12) { return31; } elseif(month==2) { return28; } else { return30; } } }classFontPopupextendsJPopupMenuimplementsActionListener//文本框字体的设置{ Stringitem[]; Fontfont[]; JMenuItemmt; JTextAreat; FontPopup(JTextAreat) { this.t=t; //this.setBorder(newBevelBorder(BevelBorder.RAISED)); item=newString[]{"标准仿宋","粗放行楷","规矩新魏","精致宋体","灵感隶书"}; font=newFont[]{ newFont("仿宋",0,18), newFont("华文行楷",0,30), newFont("华文新魏",0,22), newFont("宋体",0,14), newFont("隶书",0,18), }; for(inti=0;i<item.length;i++) { mt=newJMenuItem(item[i]); mt.setFont(newFont("仿宋",0,14)); this.add(mt); mt.addActionListener(this); }} publicvoidactionPerformed(ActionEvente) { Stringstr=e.getActionCommand(); inti; for(i=0;i<item.length;i++) if(str.equals(item[i]))break; t.setFont(font[i]); } } classNoteBookextendsJFrameimplementsActionListener,MouseListener,ChangeListener{ JTextAreatxt; JPanelp1; JLabelpic; JLabellabTxt; Containercont; JButtonbtnSave; JButtonbtnDelete; JButtonbtnInput; JButtonbtnOutput; JScrollPanejsp; Stringpass; Hashtabletable; Datekey; SimpleDateFormatsimDate; FilenoteFile; FileInputStreamnoteFileIn; staticFontsaveFont;//保存颜色 SexBoxsexBox; YearMonthyearMonth=newYearMonth(); AreaDateare; Weekweek; FontPopupfp;//设置字体// Enterword=newEnter(1); DateTimedateTime=newDateTime(1); NoteBook() { super("写字留痕V4.0bydaming"); this.setResizable(false); this.setDefaultCloseOperation(3); this.setBounds(300,100,800,600);// ymInit(); init(); this.setVisible(true); } NoteBook(inti){} publicvoidinit() { cont=this.getContentPane(); cont.setBackground(Color.blue); cont.setLayout(null); p1=newJPanel(); p1.setLayout(newGridLayout(1,3,5,5)); txt=newJTextArea(); txt.setLineWrap(true); //txt.setText((String)(table.get(20111124))); pic=newJLabel(newImageIcon("1.jpg")); btnSave=newJButton("保存"); btnDelete=newJButton("删除"); btnInput=newJButton("导入"); btnOutput=newJButton("导出"); sexBox=newSexBox();//定义选取天气 are=newAreaDate();//定义万年历放置的文本// yearMonth=newYearMonth();//定义选取时间 week=newWeek();//定义星期 jsp=newJScrollPane(txt); noteFile=newFile(Integer.toString(dateTime.year)+Integer.toString(dateTime.month) +Integer.toString(dateTime.date)+".txt"); simDate=newSimpleDateFormat("yyyyMMdd"); try{ key=simDate.parse(Integer.toString(dateTime.year)+Integer.toString(dateTime.month) +Integer.toString(dateTime.date)); } catch(Exceptione){} fp=newFontPopup(txt);//设置字体类 saveFont=newFont("宋体",0,18); labTxt=newJLabel(Integer.toString(dateTime.year)+"年"+ Integer.toString(dateTime.month)+"月"+Integer.toString(dateTime.date)+"日" );//定义时间的标签在多文本的上面 labTxt.setFont(newFont("宋体",Font.BOLD,20)); p1.add(btnSave); p1.add(btnDelete); p1.add(btnInput); p1.add(btnOutput); cont.add(p1); cont.add(jsp); cont.add(sexBox); cont.add(are); cont.add(yearMonth); //cont.add(are); cont.add(week); cont.add(pic); cont.add(labTxt); jsp.setBounds(250,50,530,450);//记事本位置 p1.setBounds(320,530,300,30);//3个按钮面板 yearMonth.setBounds(0,510,260,30);//时间选取组件位置 sexBox.setBounds(600,15,200,35);//天气选取组件位置 are.setBounds(0,300,250,200);//日期文本框位置 week.setBounds(0,270,260,30);//星期位置 pic.setBounds(5,40,240,240);//图片位置 labTxt.setBounds(350,5,250,50); btnSave.addActionListener(this); btnDelete.addActionListener(this); btnInput.addActionListener(this); btnOutput.addActionListener(this); txt.addMouseListener(this); for(inti=0;i<42;i++) are.showDay[i].addMouseListener(this); yearMonth.showYear.addChangeListener(this); yearMonth.showMonth.addChangeListener(this); yearMonth.showDate.addChangeListener(this); fileReader(); }publicvoidstateChanged(ChangeEvente){ dateTime.year=(Integer)yearMonth.showYear.getModel().getValue(); dateTime.month=(Integer)yearMonth.showMonth.getModel().getValue(); dateTime.date=(Integer)yearMonth.showDate.getModel().getValue(); System.out.println(dateTime.year); saveFile(); //newAreaDate(); newNoteBook(); this.dispose();}publicvoidactionPerformed(ActionEvente)//控件侦听 { if(e.getSource()==btnOutput) outputFile(); elseif(e.getSource()==btnInput) inputFile(); elseif(e.getSource()==btnDelete) deleteFile(); elseif(e.getSource()==btnSave) { saveFile(); JOptionPane.showMessageDialog(null,"保存成功"); } } publicvoidoutputFile()//导出文件 { pass=JOptionPane.showInputDialog("youkey?"); if(!pass.equals("321")) { JOptionPane.showMessageDialog(newJDialog(),"抱歉,你无权导出"); } else { JFileChooserfc=newJFileChooser("E:\\日记"); fc.showSaveDialog(this); Filefile=fc.getSelectedFile(); try { FileWriterout=newFileWriter(file); out.write(txt.getText()); out.close(); } catch(Exceptione) {} //pass=JOptionPane.showInputDialog("youkey?"); } } publicvoidinputFile()//导入文件 { JFileChooserfc=newJFileChooser("E:\\日记"); fc.showOpenDialog(this); Filefile=fc.getSelectedFile(); try { FileInputStreamin=newFileInputStream(file); byteb[]=newbyte[in.available()]; in.read(b); txt.setText(newString(b)); in.close(); } catch(Exceptione){} } publicvoiddeleteFile() { Objectobj=JOptionPane.showConfirmDialog(null,"是否要删除这天的记录?"); ObjectobjTest=0; if(obj==objTest) { txt.setText(""); } } publicvoidsaveFile()//保存文件 { try{ /*ObjectOutputStreamobjectOut=newObjectOutputStream(newFileOutputStream( Integer.toString(dateTime.year)+Integer.toString(dateTime.month) +Integer.toString(dateTime.date)+".txt")); objectOut.writeObject(table); objec
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 具身智能+商业零售场景顾客动线分析与优化研究报告
- 2026学年陕西省咸阳市六年级数学期末自测模拟黑金提分题(附答案)详细答案和解析
- 【新教材】外研版(2024)九年级上册英语Unit 5 A fine balance 核心素养培优测试卷(含答案解析)
- 2026年大学试题(计算机科学)-计算机基础计算机网络基础历年参考题库含答案解析
- 2026年大学试题(经济学)-公共部门经济学历年参考题库含答案解析
- 2026年国家开放大学(电大)-工商管理(本科)历年参考题库含答案解析
- 2026年卫生知识健康教育知识竞赛-GMP(药品生产质量管理规范)知识竞赛历年参考题库含答案解析
- 2026年内蒙古住院医师-内蒙古住院医师口腔病理科历年参考题库含答案解析
- 2026年其他知识竞赛-T+产品考试历年参考题库含答案解析
- 2026年业务知识竞赛-导游服务知识竞赛历年参考题库含答案解析
- 年薪保底协议劳动合同
- 汽轮机高压主气阀课件
- 第一章 机械运动 评价卷(含答案)人教版物理(2024)八年级上册
- 中职教材形象设计课件
- 《品篆刻之美》课件 2025-2026学年人美版(2024)初中美术七年级上册
- 农业园区管理课件
- 中铁品牌建设管理办法
- DZ/T 0223-2011矿山地质环境保护与恢复治理方案编制规范
- 美术步辇图课件
- 中风恢复期护理
- 污水处理基础知识+工艺培训(全)课件
评论
0/150
提交评论