简易写字板软件设计.doc

上传人:仙人指路1688 文档编号:2373511 上传时间:2023-02-16 格式:DOC 页数:24 大小:591.01KB
返回 下载 相关 举报
简易写字板软件设计.doc_第1页
第1页 / 共24页
简易写字板软件设计.doc_第2页
第2页 / 共24页
简易写字板软件设计.doc_第3页
第3页 / 共24页
简易写字板软件设计.doc_第4页
第4页 / 共24页
简易写字板软件设计.doc_第5页
第5页 / 共24页
点击查看更多>>
资源描述

《简易写字板软件设计.doc》由会员分享,可在线阅读,更多相关《简易写字板软件设计.doc(24页珍藏版)》请在三一办公上搜索。

1、华北科技学院计算机学院综合性实验报告Java程序设计B课程综合性实验报告开课实验室:基础七 2013 年 11 月 29 日实验题目简易写字板软件设计一、实验目的通过编写Java的应用系统综合实例简易写字板软件,总结、回顾和实践面向对象的编程思想以及编程方法,并通过编写程序来掌握Java语言编程技巧,将学习到的知识融会贯通,同时提高调试程序的能力,养成良好的编程习惯,并增强对程序设计整体思路的把握。熟悉在集成开发环境下编写Java程序。二、设备与环境 硬件:多媒体计算机软件:Windows 2000以上的操作系统、JDK开发包、集成开发环境三、实验内容总体要求:程序功能基本完成,用户界面友好,

2、代码的可维护性和可扩展性较好,最好包括必要的注释和相应的文档。具体要求:基本的文本录入,字符修改,删除,换行,粘贴,复制,剪切等功能,主要包括:1 菜单栏设计及功能实现:菜单栏主要包括文件、编辑、格式、帮助等常见菜单。其中文件菜单有新建、打开、保存、另存为、退出等功能;编辑菜单有剪切、复制、粘贴、等功能;格式菜单含有对文字字体、字型、字号及颜色等的设置功能,根据情况可在编辑菜单添加查找和查找替换功能。2 编辑区设计:对文本的编辑处理区。3 工具栏设计:可根据需要增加该项功能。4 其他功能设计。四、实验结果及分析1主界面的设计与实现整个界面共包括2部分包括菜单栏和编辑区,如图1所示图1 主界面

3、菜单的设计本程序共设计4个菜单,分别是文件、编辑、格式和帮助,其中文件菜单实现了5个功能,分别是新建、打开、保存、另存为和退出5个功能。编辑菜单实现了3个功能,分别是复制、剪切、粘贴3个功能。格式菜单实现了2个功能,分别是字体和颜色2个功能。帮助菜单里只有关于写字板着一个功能。各个菜单的功能见图2图2各个菜单功能 编辑区设计编辑区实现的文本录入、自动换行和右击菜单功能。如图3所示图3右击功能2文件菜单中各项功能的实现文件菜单包括新建、打开、保存、另存为和退出5部分 建功能设计当编辑区中不为空时,新健时会提醒是否保存,当点击是时怎出现另存为的对框如图4、5所示图4图5当点击否时怎文本区清空。 开

4、功能设计打开实现了在打开本地文件的功能,选择本地文件并打开在当前窗口。如图6所示。图6打开 存功能设计保存实现了在当前路径下保存当前文档,若无路径则添加路径。若有的话直接保存如图7所示。图7保存 存为功能设计另存为实现了在新路径下保存当前文档的功能。如图8所示。图8另存为 出功能设计退出实现了用户退出是提醒用户是否确定要退出。如图9所示图9退出2.编辑菜单中各项功能的实现编辑菜单包括剪切、复制、粘贴3部分,如图 10所示。图101 剪切功能设计剪切实现了对所选文本的剪切。2 复制功能设计复制实现了对所选文本的复制。3 粘贴功能设计粘贴实现了对当前文档剪贴板的粘贴。3格式菜单中各项功能的实现格式

5、菜单包括设置字体、字体颜色2部分,如图11所示。图11颜色图12颜色4帮助菜单中各项功能的实现帮助菜单包括查看“关于记事本”如图13 所示图13关于记事本3收获与体会听懂的不一定会做的出来只有实际中实实在在的做出来的才是自己的,经过这十几的不懈努力终于把自己的写字板给做了出来了,虽然比起真正的写字板要查很多,还有许多功能需要完善,但是这毕竟是在自己的努力下做出来的成功,还是高兴的。在实际的操作中才逐渐的发现自己的不足,和实际当中的眼高手低的问题,总感觉自己都听懂了可实际操作下才明白这是有多么的差劲。在用java的整个界面设计中不仅体现了自己编程能力更是要求自己对整个布局的把握通过不断的参考资料

6、弥补了自己的不足同时也学到了很多课外的知识,是自己在对java综合知识的利用中更加熟练。从中体会到了java编程的乐趣。但是在java编程中这只是一个开头还有更多的知识需要我去把握,去学习。从而在java方面走的更高。在这里感谢李老师这学期的教导,谢谢老师附录import java.awt.*;import java.awt.event.*;import javax.swing.*;import java.io.*;public class notepublic static void main(String args)new noted();class noted extends JFram

7、e implements ActionListenerJMenuBar menu1;JMenu file1,edit,form,help;JMenuItem newfile,open,save,assave,exit,copy,cut,paste,find,replace,font1,color1,something,copy1,cut1,paste1,aboutnote;JTextArea area;JScrollPane pane;JPopupMenu menu2;/弹出式菜单JFileChooser filechooser;public noted() setTitle(无标题-写字板)

8、; setBounds(200,200,600,400);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);area=new JTextArea(10,15);area.setLineWrap(true);area.setFont(new Font(宋体,Font.PLAIN,14);pane=new JScrollPane(area);add(pane,BorderLayout.CENTER);menu1=new JMenuBar();menu2=new JPopupMenu();file1=new JMenu(文

9、件);edit=new JMenu(编辑);form=new JMenu(格式);help=new JMenu(帮助);filechooser=new JFileChooser();/文件及其相关项的设置于添加newfile=new JMenuItem(新建);newfile.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK);open=new JMenuItem(打开);open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEv

10、ent.CTRL_MASK);save=new JMenuItem(保存);save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK);assave=new JMenuItem(另存为);assave.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK);exit=new JMenuItem(退出);exit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.V

11、K_X,InputEvent.CTRL_MASK);file1.add(newfile);file1.add(open);file1.add(save);file1.add(assave);file1.addSeparator();file1.add(exit);menu1.add(file1);/编辑及其子项的添加copy=new JMenuItem(复制);copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK);cut=new JMenuItem(剪切);cut.setAccelerato

12、r(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK);paste=new JMenuItem(粘贴);paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK);/find=new JMenuItem(查找);/find.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,InputEvent.CTRL_MASK);/replace=new JMenuItem(替换);/rep

13、lace.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,InputEvent.CTRL_MASK);edit.add(copy);edit.add(cut);edit.add(paste);/edit.addSeparator();/edit.add(find);/edit.add(replace);menu1.add(edit);/格式及其子项的添加font1=new JMenuItem(字体);color1=new JMenuItem(颜色);form.add(font1);form.add(color1);menu1.add(fo

14、rm);/帮助及其子项的添加aboutnote=new JMenuItem(关于写字板);help.add(aboutnote);menu1.add(help);setJMenuBar(menu1);/菜单条的设置/鼠标右击的添加copy1=new JMenuItem(复制);copy1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK);cut1=new JMenuItem(剪切);cut1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,I

15、nputEvent.CTRL_MASK);paste1=new JMenuItem(粘贴);paste1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK);menu2.add(copy1);menu2.add(cut1);menu2.add(paste1);copy.addActionListener(this);copy1.addActionListener(this);cut.addActionListener(this);cut1.addActionListener(this);paste.

16、addActionListener(this);paste1.addActionListener(this);color1.addActionListener(this);newfile.addActionListener(this);open.addActionListener(this);assave.addActionListener(this);save.addActionListener(this);exit.addActionListener(this);font1.addActionListener(this);aboutnote.addActionListener(this);

17、/find.addActionListener(this);validate();area.addMouseListener(new MouseAdapter()public void mousePressed(MouseEvent e)if(e.getModifiers()=InputEvent.BUTTON3_MASK)menu2.show(area,e.getX(),e.getY(););/新建public void newfile()if(!area.getText().equals()int t=JOptionPane.showConfirmDialog(this,是否保存?,提示保

18、存,JOptionPane.YES_NO_CANCEL_OPTION);if(t=JOptionPane.YES_OPTION)save();setTitle(无标题-写字板);area.setText();if(t=JOptionPane.NO_OPTION)setTitle(无标题-写字板);area.setText();/打开public void open()area.setText(null);int n=filechooser.showOpenDialog(null);if(n=JFileChooser.APPROVE_OPTION)File file1=filechooser.g

19、etSelectedFile();setTitle(file1.getName();tryFileReader readerfile=new FileReader(file1);BufferedReader in=new BufferedReader(readerfile);String s=null;while(s=in.readLine()!=null)area.append(s+n);catch(IOException ee)/保存public void save()int n=filechooser.showDialog(null,另存为);if(n=JFileChooser.APPR

20、OVE_OPTION)File file2=filechooser.getSelectedFile();if(!file2.exists()setTitle(file2.getName();tryFileWriter writerfile=new FileWriter(file2);BufferedWriter out=new BufferedWriter(writerfile);out.write(area.getText();out.close();writerfile.close();catch(IOException eee)elseint m=JOptionPane.showConf

21、irmDialog(this,file2.getName()+n+已存在,是否要覆盖?,确认另存为,JOptionPane.YES_NO_OPTION);if(m=JOptionPane.YES_OPTION)setTitle(file2.getName();tryFileWriter writerfile=new FileWriter(file2);BufferedWriter out=new BufferedWriter(writerfile);out.write(area.getText();out.flush();out.close();writerfile.close();catch

22、(IOException eee)public void actionPerformed(ActionEvent e)String content=area.getText();/得到文本域中的内容if(e.getSource()=newfile)newfile();if(e.getSource()=open)open();if(e.getSource()=save)if(getTitle().equals(无标题-写字板)save();elseFile file1=filechooser.getSelectedFile();if(file1.exists()tryFileWriter wri

23、terfile=new FileWriter(file1);BufferedWriter out=new BufferedWriter(writerfile);out.write(area.getText();out.flush();out.close();writerfile.close();catch(IOException eee)if(e.getSource()=assave)save();if(e.getSource()=exit)if(!area.getText().equals()int t=JOptionPane.showConfirmDialog(this,退出之前是否保存,

24、退出提示,JOptionPane.YES_NO_OPTION);if(t=JOptionPane.YES_OPTION)save();System.exit(0);elseSystem.exit(0);System.exit(0);if(e.getSource()=copy|e.getSource()=copy1)area.copy();if(e.getSource()=cut|e.getSource()=cut1)area.cut();if(e.getSource()=paste|e.getSource()=paste1)area.paste();/*if(e.getSource()=fin

25、d)findDialog findD=new findDialog(this);*/if(e.getSource()=color1)Color newColor=JColorChooser.showDialog(this,字体颜色,area.getForeground();area.setForeground(newColor);if(e.getSource()=font1)fontframe fontfr=new fontframe(this);if(e.getSource()=aboutnote)JOptionPane.showMessageDialog(this,写字板1.0n +本软件

26、用UltraEdit开发制作!n +如有任何疑问及改善意见,随时欢迎指出,n +本人将尽最大的努力满足您的需求!n +谢谢您的使用!n版权所有,请勿侵权!n +如有雷同,纯属抄袭!,关于写字板,JOptionPane.INFORMATION_MESSAGE);/*class findDialog extends JDialog implements ActionListenerJLabel findLabel=new JLabel(查找内容);JLabel fang=new JLabel(方向);JTextField findtext=new JTextField(10);JButton fi

27、ndButton=new JButton(查找下一个);JButton canCle=new JButton(取消);JRadioButton up=new JRadioButton(向上);JRadioButton down=new JRadioButton(向下,true);ButtonGroup buGroup=new ButtonGroup();noted note1;findDialog(noted note1)this.note1=note1;setBounds(300,400,440,100);setVisible(true);setLayout(null);findLabel.

28、setBounds(10,10,60,20);findtext.setBounds(80,10,200,20);fang.setBounds(10,40,60,20);findButton.setBounds(300,10,110,20);canCle.setBounds(300,40,110,20);up.setBounds(80,40,60,20);down.setBounds(150,40,60,20);buGroup.add(up);buGroup.add(down);add(findLabel);add(findtext);add(fang);add(findButton);add(

29、canCle);add(up);add(down);findButton.addActionListener(this);validate();public void actionPerformed(ActionEvent e)/if(e.getSource()=down)if(e.getSource()=findButton)int n,m;m=note1.area.getCaretPosition();System.out.println(m);String areatext=note1.area.getText();String findt=findtext.getText();int

30、length1=areatext.length();System.out.println(length1);int length2=findt.length();if(m=length1)JOptionPane.showMessageDialog(this,findt+不存在!,查找提示,JOptionPane.INFORMATION_MESSAGE);elsen=areatext.indexOf(findt,m);note1.area.select(n,n+length2);*/class fontframe extends JFrame implements ActionListenerJ

31、ComboBox listFont,listFont1,listFont2;JLabel zt=new JLabel(字体);JLabel zx=new JLabel(字形);JLabel dx=new JLabel(大小);JLabel sL=new JLabel(字体示例);JButton ok=new JButton(确定);JButton cancle=new JButton(取消);private String ztt=宋体;private int zxx=Font.PLAIN;private intdxx=14;noted not;fontframe(noted not)this.

32、not=not;setTitle(字体);setBounds(200,200,500,300);setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);setVisible(true);Container cp=getContentPane();cp.setLayout(null);GraphicsEnvironment ge=GraphicsEnvironment.getLocalGraphicsEnvironment();String fontName=ge.getAvailableFontFamilyNames();listFont=new J

33、ComboBox(fontName);listFont.setSelectedItem(宋体);String font1=常规,斜体,粗体,斜体加粗体;listFont1=new JComboBox(font1);listFont1.setSelectedItem(常规);String font2=12,14,15,16,18,20,21,22,24,34,36,42,48,72;listFont2=new JComboBox(font2);zt.setBounds(40,30,40,20);listFont.setBounds(40,60,100,20);zx.setBounds(180,3

34、0,40,20);listFont1.setBounds(180,60,100,20);dx.setBounds(320,30,40,20);listFont2.setBounds(320,60,100,20);sL.setBounds(180,100,400,100);ok.setBounds(80,200,80,20);cancle.setBounds(300,200,80,20);sL.setFont(new Font(ztt,zxx,dxx);ok.addActionListener(this);cancle.addActionListener(this);listFont.addIt

35、emListener(new ItemListener()public void itemStateChanged(ItemEvent ee)JComboBox jb=(JComboBox)ee.getSource();ztt=(String)jb.getSelectedItem();sL.setFont(new Font(ztt,zxx,dxx););listFont1.addItemListener(new ItemListener()public void itemStateChanged(ItemEvent ee)JComboBox jb=(JComboBox)ee.getSource

36、();if(String)jb.getSelectedItem().equals(常规)zxx=Font.PLAIN;if(String)jb.getSelectedItem().equals(斜体)zxx=Font.ITALIC;if(String)jb.getSelectedItem().equals(粗体)zxx=Font.BOLD;if(String)jb.getSelectedItem().equals(斜体加粗体)zxx=Font.BOLD+Font.ITALIC;sL.setFont(new Font(ztt,zxx,dxx););listFont2.addItemListene

37、r(new ItemListener()public void itemStateChanged(ItemEvent ee)JComboBox jb=(JComboBox)ee.getSource();dxx=Integer.parseInt(String)jb.getSelectedItem();sL.setFont(new Font(ztt,zxx,dxx););cp.add(ok);cp.add(cancle);cp.add(listFont);cp.add(zt);cp.add(zx);cp.add(listFont1);cp.add(dx);cp.add(listFont2);cp.add(sL);validate();public void actionPerformed(ActionEvent e)if(e.getSource()=cancle)dispose();if(e.getSource()=ok)Font f=sL.getFont();not.area.setFont(f);dispose();教 师 评 价评定项目ABCD评定项目ABCD算法正确界面美观,布局合理程序结构合理操作熟练语法、语义正确解析完整实验结果正确文字流畅报告规范题解正确其他:评价教师签名:2013年 12 月 6 日第 23 页

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号