用Java程序编写一个记事本程序的设计报告(共25页).doc
《用Java程序编写一个记事本程序的设计报告(共25页).doc》由会员分享,可在线阅读,更多相关《用Java程序编写一个记事本程序的设计报告(共25页).doc(25页珍藏版)》请在得力文库 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上用Java程序编写一个记事本程序的设 计 报 告学习中心(点): 泾阳学习中心 专 业 : 计算机科学与技术 层 次 : 专升本 姓 名 : 李 永 固 批 次 : 112 目 录一、设计分析1二、程序结构1三、各模块的功能及程序说明21、类设计22、主要功能代码实现4四、源程序9五、操作方法20六、试验结果20七、设计体会22专心-专注-专业用Java程序编写一个记事本程序的设计报告一、设计要求1.用图形用户界面实现。2.能实现编辑、保存、另存为、查找替换等功能。二、程序结构流程图:图1基本流程图本Java文本编辑器功能设计如下:图2基本功能图三、各模块的功能及程序
2、说明1、类设计(1)类MiniText ,包括 initTextPane方法初始化面板, initMenu()方法初始化菜单, initAboutDialog()方法初始化关于对话框, initToolBar()方法初始化工具栏, initRightKey()方法初始化右键设置,等方法。类成员如下:(2)类Loading (实现登陆)类成员如下: (3)类runtime (实现时间同步)类成员如下:(4)类MainFunction (包含主函数)类成员如下:2、主要功能代码实现(1)登陆界面:class Loading extends JWindow implements Runnable T
3、hread dluThread=null; private JProgressBar progress; public Loading() setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR);/设置光标为等待状态 JPanel dlu = new JPanel(new BorderLayout(); URL url = getClass().getResource(/images/loading.jpg); if(url != null) dlu.add(new JButton(new ImageIcon(url), BorderL
4、ayout.CENTER); progress = new JProgressBar(1,100); progress.setStringPainted(true); progress.setBorderPainted(true); progress.setBackground(Color.white); progress.setForeground(Color.green); dlu.add(progress,BorderLayout.SOUTH); setContentPane(dlu); /设置窗口属性为登陆面板属性 Dimension screen = getToolkit().get
5、ScreenSize(); pack(); /显示登陆界面 setLocation(screen.width/4,screen.height/4); /设置登陆界面始终在屏幕中间显示 public void start() / this.toFront(); dluThread=new Thread(this); dluThread.start(); public void run() show(); try for (int i=0;i100;i+) Thread.sleep(100); progress.setValue(progress.getValue() + 1); progress
6、.setString(欢迎进入迷你编辑,请稍后. . +i+%); catch (Exception ex) ex.printStackTrace(); dispose();/关闭登陆界面 (2).时间标签: class runtime extends JButton implements Runnable Thread datetime=null; public runtime() public void run() for(;) /java.util.Date timeer=new java.util.Date(); Calendar now=Calendar.getInstance();
7、 int year1=now.get(Calendar.YEAR); int month1=now.get(Calendar.MONTH); int day1=now.get(Calendar.DAY_OF_MONTH); int hour1=now.get(Calendar.HOUR); int minute1=now.get(Calendar.MINUTE); int sec=now.get(Calendar.SECOND); setText(year1+年+month1+月+day1+日 +hour1+:+minute1+:+sec); /System.out.println(now.g
8、et(Calendar.DAY_OF_MONTH)-60); try Thread.currentThread().sleep(1000); catch(InterruptedException e) (3)右键的实现:void initRightKey ()filepopup=new JPopupMenu();uundo=new JMenuItem(撤消(U);uundo.setMnemonic(U);ccut=new JMenuItem(剪切(T);ccut.setMnemonic(T);ccopy=new JMenuItem(复制(C);ccopy.setMnemonic(C);ppas
9、te=new JMenuItem(粘贴(V);ppaste.setMnemonic(V);ddelete=new JMenuItem(删除(D);ddelete.setMnemonic(D);sselectall=new JMenuItem(全选(A);sselectall.setMnemonic(A);filepopup.add(uundo);filepopup.addSeparator();filepopup.add(ccut);filepopup.add(ccopy);filepopup.add(ppaste);filepopup.add(ddelete);filepopup.addSe
10、parator();filepopup.add(sselectall);uundo.addActionListener(action);ccut.addActionListener(action);ccopy.addActionListener(action);ppaste.addActionListener(action);ddelete.addActionListener(action);sselectall.addActionListener(action);text.addMouseListener(new MouseAdapter()public void mousePressed(
11、MouseEvent event)checkForTriggerEvent(event);public void mouseReleased(MouseEvent event)checkForTriggerEvent(event);public void checkForTriggerEvent(MouseEvent event)if(event.isPopupTrigger()filepopup.show(event.getComponent(),event.getX(),event.getY();); (4)打开、保存、复制、粘贴、撤销等功能事件响应实现:/事件处理 ActionListe
12、ner action = new ActionListener() public void actionPerformed(ActionEvent e) JMenuItem mi = (JMenuItem)e.getSource(); String id = mi.getText(); if(id.equals(新建) Date date=new Date(); text.setText(date.toString(); file = null; else if(id.equals(打开.) if(file != null) filechooser.setSelectedFile(file);
13、/为用户选择文件提供了一种简单的机制 int returnVal = filechooser.showOpenDialog(MiniText.this); if(returnVal = JFileChooser.APPROVE_OPTION) file = filechooser.getSelectedFile(); openFile(); else if(id.equals(保存.) if(file != null) filechooser.setSelectedFile(file); int returnVal = filechooser.showSaveDialog(MiniText.t
14、his); if(returnVal = JFileChooser.APPROVE_OPTION) file = filechooser.getSelectedFile(); saveFile(); JOptionPane.showMessageDialog(null,已保存); else if(id.equals(另存为) if(file != null) filechooser.setSelectedFile(file); int returnVal = filechooser.showSaveDialog(MiniText.this); if(returnVal = JFileChoos
15、er.APPROVE_OPTION) file = filechooser.getSelectedFile(); saveFile(); JOptionPane.showMessageDialog(null,已保存); else if(id.equals(打印) prt.printDialog(); else if(id.equals(打印页面设置)try prt.print(); catch(Exception ew) JOptionPane.showMessageDialog(null,打印出错!,错误,JOptionPane.ERROR_MESSAGE); else if(id.equa
16、ls(退出) System.exit(0); else if(id.equals(剪切)|id.equals(剪切(T) text.cut(); else if(id.equals(复制)|id.equals(复制(C) text.copy(); else if(id.equals(粘贴)|id.equals(粘贴(V) text.paste(); else if(id.equals(删除)|id.equals(删除(D) text.replaceSelection(); else if(id.equals(选择全部)|id.equals(全选(A) text.selectAll(); els
17、e if(id.equals(字体颜色.) color = JColorChooser.showDialog(MiniText.this,字体颜色设置,color); text.setForeground(color); else if(id.equals(自动换行) else if(id.equals(撤销)|id.equals(撤消(U) text.setText(); text.selectAll(); else if(id.equals(查找) String find=查找; find=JOptionPane.showInputDialog(查找:); else if(id.equal
18、s(时间) time.setFont(new Font(Times New Roman,Font.PLAIN,12); text.insertComponent(time); else if(id.equals(系统 记事本)try String command = notepad.exe;Process child = Runtime.getRuntime().exec(command);/从系统进程中调用记事本 catch (IOException ex) else if(id.equals(系统 计算器) try String command = calc.exe; Process ch
19、ild = Runtime.getRuntime().exec(command);/调用系统计算器 catch (IOException ex) else if(id.equals(关于) about.setSize(250,150); about.show(); ;四、源程序import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.io.*; public class Notepad extends JFrame / 系统组件声明 private JMenuBar menuBar = new J
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Java 程序 编写 一个 记事本 设计 报告 25
限制150内