用Java程序编写一个记事本程序的设计报告.docx
-
资源ID:623709
资源大小:170.88KB
全文页数:25页
- 资源格式: DOCX
下载积分:5金币
友情提示
2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
|
用Java程序编写一个记事本程序的设计报告.docx
用Java程序编写一个记事本程序的设计报告学习中心(点):泾阳学习中心专业:计算机科学与技术层次:专升本姓名:李永固批次:112目录一、设计分析1二、程序结构1三、各模块的功能及程序说明21、类设计22、主要功能代码实现4四、源程序9五、操作方法20六、试验结果20七、设计体会22用Java程序编写一个记事本程序的设计报告一、设计要求1.用图形用户界面实现。2.能实现编辑、保存、另存为、查找替换等功能。二、程序结构流程图:图1基本流程图本JaVa文本编辑器功能设计如下:基本功能图2基本功能图各模块的功能及程序说明U类设计(1)类MiniTeXt,包括initTextPane方法初始化面板,initMenu()方法初始化菜单,InitAboutDiaIogO方法初始化关于对话框,initToolBar()方法初始化工具栏,MitRightKeyO方法初始化右键设置,等方法。类成员如下:,三厚天言萌二:file:Filecolor:ColorgetFont:GraphiCsEnviroiunentAfonts:Fonttext:JTextPanefilechooser:JFileChoosercolorchooser:JCoIorChoOSerabout:JlHaIogmenubar:JMenuBariiprt:Printerjobdate:GregoriaikCalendrt:Stringtime:JLabeldatetime:runtimeO1.-otoolbar:JToolBarfIlepopup:JPoPUPMenUUUndo:JMenuItemOQ0ccut:JMenuItemccopy.JMenultemPPaSte:JMenUItemi,-三Oddelete:JMenUltem».I"*Ae必ASselectallJMexHlIteminitRightKeyOrMiniTextOinitTextPaneOmenus:JMenuIBenuitems:JMenuIteminitMenuOaction:ActioxiListenerSaVeFiieOopenFileOinitAboutDialogbuttons:JButtoninitToolBarO(2)类LOading(实现登陆)类成员如下:W导入声明(UuThread:Threadprogress.JProgressBar.cLoading。0startO求人runO(3)类runtime(实现时间同步)类成员如下:O导入声明datetime:ThreadCruntime0CArun()(4)类MainFUnCtiOn(包含主函数)类成员如下:/三i三HjQSmain(Strng)2、主要功能代码实现(1)登陆界面:classLoadingextendsJWindowimplementsRunnableThreaddluThread=null;privateJProgressBarprogress;publicLoadingOSetCUrSor(CUrSor.getPredefinedCurs0r(Cursor.WAIT-CURSOR);/设置光标为等待状态JPaneIdlu=newJPaneKnewBorderLayoutO);URLurl=getClass().getResource(,VimagesZloadingjpg");if(url!=null)dl.add(newJButton(newImageIcon(Url),BorderLayout-CENTER);progress=newJProgressBar(1,100);progress.SetStringPainted(Irue);progress.setBorderPainted(true);progress.setBackground(Color.white);progress.setForeground(Color.green);dlu.add(progress,BorderLayout.SOUTH);setContentPane(dlu);设置窗口属性为登陆面板属性Dimensionscreen=getToolkit().getScreenSize();pack();"显示登陆界面setLocation(screen.width4,screen.height/4);设置登陆界面始终在屏幕中间显示publicvoidstart()Hthis.toFront();dluThread=newThread(Ihis);dluThread.start();publicvoidrun()show。;tryfor(inti=0ji<100ji+÷)Thread,sleep(100);progress.setValue(progress.getValue()+1);progress.setString(,'欢迎进入迷你编辑,请稍后,+i+%,);catch(Exceptionex)ex.printStackTrace();dispose。;/关闭登陆界面(2)时间标签:classruntimeextendsJButtonimplementsRunnableThreaddatetime=null;publicruntime()publicvoidrun()for(;)/java.utiLDatetineer=newjava.util.Date();Calendarnow=Calendar.getlnstance();intyearl=now.get(Calendar.YEAR);intOionthl=IiOWaget(CalendarAlONTH);intdayl=now.get(Calendar.DAY_OF_MONTH);inthourl=now.get(Calendar.HOUR);intminute1=now.get(CalendarAlINUTE);intsec=now.get(CalendanSECOND);setText(yearl÷,*年“+nwnthl+"月”+dayl+“日''+hourl+'!'+minutel+'T'+sec);/Systeni.out.println(now.get(Calendar.DAY_OF_MONTH)-60);UyThread.currentThread().sleep(1000);catch(InterruptedExceptione)(3)右键的实现:voidinitRightKey()filepopup=new.PopupMenu();IlIIiId=IIeWJMeIlIIItem(”撤消(U)");uundo.setMnemonic(*U*);CCilt=IWWJMeIlUltem("剪切(T)");ccuLsetMnemonic(,T,);CCOPy=newJMenuItemr复制(C)”);ccopy.setMnenonic(,C1);ppaste=newJMenIlItem("粘贴(V)");ppaste.setMnemonic(,V,);ddelete=newJMenuItemC'删除(D)");ddeletesetMnemonic('D');SSeIectall=DewJMeIlUltem(”全选(八)");sselectall.setMnemonic('A1);filepopup.add(uundo);11lepopup.addSeparator();lepopup.add(ccut);filepopup.add(ccopy);filepopup.add(ppaste);filepopup.add(ddelete);lepopup.addSeparator();filepopup.add(sselectall);uundoaddActionListener(action);ccuLaddActionListener(action);CCOPy.addActionListener(action);ppaste.addActionListener(action);ddelete.addActionListener(action);sselectall.addActionListener(action);text.addMouseListener(newMouseAdapter()publicvoidnousePressed(MouseEventevent)checkForTriggerEvent(event);publicvoidHiouseReleasedfMouseEventevent)=WORD完整版.一可编辑-专业资料分享=checkForTrgerEvent(event);publicvoidCheckForTrigerEvent(MouseEventevent)if(event.isPopupTrigger()filepopup.show(event.getComponent(),event.getX(),event.getY(););(4)打开、保存、复制、粘贴、撤销等功能事件响应实现:/事件处理ActionListeneraction=newActionListenerOpublicvoidactionPerforned(ActionEvente)JMenuItenimi=(JMenuIten)egetSource();Stringid=mi.getText();if(idequals("新建”)Datedate=newDate();text.setText(date.toString();file=null;elseif(id.equals(”打开”)if(file!=null)f0echoosersetSelectedFile(file);为用户选择文件提供了一种简单的机制intreturnVal=(IIeChOOSer.ShowOpenDialog(MiniTexLthis);if(returnVal=JFileChoosenAPPROVE.OPTION)file=filechooser.getSelectedFile();OPenFile0;elseif(idequals(”保存”)if(file!=null)filechooser.setSelectedFile(file);intreturnVal=flechoosenshowSaveDialog(MiniText.this);if(returnVal=JFileCho