您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 用Java程序编写一个记事本程序的设计报告
用Java程序编写一个记事本程序的设计报告学习中心(点):泾阳学习中心专业:计算机科学与技术层次:专升本姓名:李永固批次:112目录一、设计分析····················································1二、程序结构····················································1三、各模块的功能及程序说明·······························21、类设计····················································22、主要功能代码实现·····································4四、源程序·······················································9五、操作方法····················································20六、试验结果····················································20七、设计体会····················································22-1-用Java程序编写一个记事本程序的设计报告一、设计要求1.用图形用户界面实现。2.能实现编辑、保存、另存为、查找替换等功能。二、程序结构流程图:调用Loading方法启动dluThread线程登陆界面开始dluThread线程结束后调用MiniText()方法启动MainFunction的主函数main()调用initTextPane(方法初始化面板调用initMenu()方法初始化菜单调用initAboutDialog()方法初始化关于对话框调用initToolBar()方法初始化工具栏调用initRightKey()方法初始化右键设置启动runtime线程创建动态时间按钮退出图1基本流程图-2-本Java文本编辑器功能设计如下:基本功能文件格式编辑查看帮助工具新建、打开、保存、另存为、打印等复制、粘贴、删除、撤销等自动换行字体颜色系统记事本系统计算器关于查找时间图2基本功能图三、各模块的功能及程序说明1、类设计(1)类MiniText,包括initTextPane方法初始化面板,initMenu()方法初始化菜单,initAboutDialog()方法初始化关于对话框,initToolBar()方法初始化工具栏,initRightKey()方法初始化右键设置,等方法。类成员如下:-3-(2)类Loading(实现登陆)类成员如下:-4-(3)类runtime(实现时间同步)类成员如下:(4)类MainFunction(包含主函数)类成员如下:2、主要功能代码实现(1)登陆界面:classLoadingextendsJWindowimplementsRunnable{ThreaddluThread=null;privateJProgressBarprogress;publicLoading(){setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));//设置光标为等待状态JPaneldlu=newJPanel(newBorderLayout());URLurl=getClass().getResource(/images/loading.jpg);if(url!=null){dlu.add(newJButton(newImageIcon(url)),BorderLayout.CENTER);}progress=newJProgressBar(1,100);progress.setStringPainted(true);progress.setBorderPainted(true);progress.setBackground(Color.white);progress.setForeground(Color.green);dlu.add(progress,BorderLayout.SOUTH);setContentPane(dlu);//设置窗口属性为登陆面板属性Dimensionscreen=getToolkit().getScreenSize();pack();//显示登陆界面setLocation(screen.width/4,screen.height/4);//设置登陆界面始终在屏幕中间显示}publicvoidstart(){//this.toFront();dluThread=newThread(this);dluThread.start();}publicvoidrun(){show();-5-try{for(inti=0;i100;i++){Thread.sleep(100);progress.setValue(progress.getValue()+1);progress.setString(欢迎进入迷你编辑,请稍后......+i+%);}}catch(Exceptionex){ex.printStackTrace();}dispose();//关闭登陆界面}}(2).时间标签:classruntimeextendsJButtonimplementsRunnable{Threaddatetime=null;publicruntime(){}publicvoidrun(){for(;;){//java.util.Datetimeer=newjava.util.Date();Calendarnow=Calendar.getInstance();intyear1=now.get(Calendar.YEAR);intmonth1=now.get(Calendar.MONTH);intday1=now.get(Calendar.DAY_OF_MONTH);inthour1=now.get(Calendar.HOUR);intminute1=now.get(Calendar.MINUTE);intsec=now.get(Calendar.SECOND);-6-setText(year1+年+month1+月+day1+日+hour1+:+minute1+:+sec);//System.out.println(now.get(Calendar.DAY_OF_MONTH)-60);try{Thread.currentThread().sleep(1000);}catch(InterruptedExceptione){}}}}(3)右键的实现:voidinitRightKey(){filepopup=newJPopupMenu();uundo=newJMenuItem(撤消(U));uundo.setMnemonic('U');ccut=newJMenuItem(剪切(T));ccut.setMnemonic('T');ccopy=newJMenuItem(复制(C));ccopy.setMnemonic('C');ppaste=newJMenuItem(粘贴(V));ppaste.setMnemonic('V');ddelete=newJMenuItem(删除(D));ddelete.setMnemonic('D');sselectall=newJMenuItem(全选(A));sselectall.setMnemonic('A');filepopup.add(uundo);filepopup.addSeparator();filepopup.add(ccut);filepopup.add(ccopy);filepopup.add(ppaste);filepopup.add(ddelete);filepopup.addSeparator();filepopup.add(sselectall);uundo.addActionListener(action);ccut.addActionListener(action);-7-ccopy.addActionListener(action);ppaste.addActionListener(action);ddelete.addActionListener(action);sselectall.addActionListener(action);text.addMouseListener(newMouseAdapter(){publicvoidmousePressed(MouseEventevent){checkForTriggerEvent(event);}publicvoidmouseReleased(MouseEventevent){checkForTriggerEvent(event);}publicvoidcheckForTriggerEvent(MouseEventevent){if(event.isPopupTrigger()){filepopup.show(event.getComponent(),event.getX(),event.getY());}}});}(4)打开、保存、复制、粘贴、撤销等功能事件响应实现://事件处理ActionListeneraction=newActionListener(){publicvoidactionPerformed(ActionEvente){JMenuItemmi=(JMenuItem)e.getSource();Stringid=mi.getText();if(id.equals(新建)){Datedate=newDate();text.setText(date.toString());file=null;}elseif(id.equals(打开...)){if(file!=null)filechooser.setSelectedFile(file);//为用户选择文件提供了一种简单的机制-8-intreturnVal=filechooser.showOpenDialog(MiniText.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=filechooser.getSelectedFile();openFile();}}elseif(id.equals(保存...)){if(file!=null)filechooser.setSelectedFile(file);intreturnVal=filechooser.showSaveDialog(MiniText.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=filechooser.getSelectedFile();saveFile();JOptionPane.showMessageDialog(null,已保存);}}elseif(id.equals(另存为)){if(file!=null)filechooser.setSelectedFile(file);intreturnVal=filechooser.showSaveDialog(MiniText.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=filechooser.getSelectedFile();saveFile();JOptionPane.showMessageDialog(null,已保存);}}elseif(id.equals(打印)){prt.printDialog();}elseif(id.equals(打印页面设置)){try{prt.print();}catch(Exceptionew){JO
本文标题:用Java程序编写一个记事本程序的设计报告
链接地址:https://www.777doc.com/doc-7327612 .html