欢迎来到三一文库! | 帮助中心 三一文库31doc.com 一个上传文档投稿赚钱的网站
三一文库
全部分类
  • 研究报告>
  • 工作总结>
  • 合同范本>
  • 心得体会>
  • 工作报告>
  • 党团相关>
  • 幼儿/小学教育>
  • 高等教育>
  • 经济/贸易/财会>
  • 建筑/环境>
  • 金融/证券>
  • 医学/心理学>
  • ImageVerifierCode 换一换
    首页 三一文库 > 资源分类 > DOC文档下载
     

    《Java程序设计》课程综合性实验报告-简易写字板软件设计.doc

    • 资源ID:5091380       资源大小:487.50KB        全文页数:24页
    • 资源格式: DOC        下载积分:6
    快捷下载 游客一键下载
    会员登录下载
    微信登录下载
    三方登录下载: 微信开放平台登录 QQ登录   微博登录  
    二维码
    微信扫一扫登录
    下载资源需要6
    邮箱/手机:
    温馨提示:
    用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)
    支付方式: 支付宝    微信支付   
    验证码:   换一换

    加入VIP免费专享
     
    账号:
    密码:
    验证码:   换一换
      忘记密码?
        
    友情提示
    2、PDF文件下载后,可能会被浏览器默认打开,此种情况可以点击浏览器菜单,保存网页到桌面,就可以正常下载了。
    3、本站不支持迅雷下载,请使用电脑自带的IE浏览器,或者360浏览器、谷歌浏览器下载即可。
    4、本站资源下载后的文档和图纸-无水印,预览文档经过压缩,下载后原文更清晰。
    5、试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。

    《Java程序设计》课程综合性实验报告-简易写字板软件设计.doc

    华北科技学院计算机系综合性实验报告华北科技学院计算机系综合性实验实 验 报 告 课程名称 Java程序设计 实验学期 2011 至 2012 学年 第 1 学期学生所在系部 基础部 年级 2009 专业班级 计算B092 学生姓名 学号 任课教师 实验成绩 计算机系制Java程序设计课程综合性实验报告开课实验室: 基础实验室 2011 年 12 月 5 日实验题目简易写字板软件设计一、 实验目的i. 通过编写Java的应用系统综合实例简易写字板软件,总结、回顾和实践面向对象的编程思想以及编程方法,并通过编写程序来掌握Java语言编程技巧,将学习到的知识融会贯通,同时提高调试程序的能力,养成良好的编程习惯,并增强对程序设计整体思路的把握。ii. 熟悉在集成开发环境下编写Java程序。二、 设备与环境iii. 硬件:多媒体计算机iv. 软件:Windows 2000以上的操作系统、JDK开发包、集成开发环境三、 实验内容v. 总体要求:程序功能基本完成,用户界面友好,代码的可维护性和可扩展性较好,最好包括必要的注释和相应的文档。vi. 具体要求:基本的文本录入,字符修改,删除,换行,粘贴,复制,剪切等功能,主要包括:2. 菜单栏设计及功能实现:菜单栏主要包括文件、编辑、格式、帮助等常见菜单。其中文件菜单有新建、打开、保存、另存为、退出等功能;编辑菜单有剪切、复制、粘贴、等功能;格式菜单含有对文字字体、字型、字号及颜色等的设置功能,根据情况可在编辑菜单添加查找和查找替换功能。3. 编辑区设计:对文本的编辑处理区。4. 工具栏设计:可根据需要增加该项功能。5. 其他功能设计。四、 实验结果及分析1 主界面的设计与实现a) 整个界面共包括四个部分,包括:标题栏、菜单栏、编辑区、状态栏以及滚动条,如图1所示。b)6. 图表 1记事本的整体布局menuBar=new JMenuBar();setJMenuBar(menuBar);menu=new JMenu5;menuItem=new JMenuItemmenu.length;menu0=new JMenu("文件(F)");menu0.setMnemonic('F');menu1=new JMenu("编辑(E)");menu1.setMnemonic('E');menu2=new JMenu("格式(O)");menu2.setMnemonic('O');menu3=new JMenu("查看(V)");menu3.setMnemonic('V');menu4=new JMenu("帮助(H)");menu4.setMnemonic('H');7. 菜单的设计a) 本程序共设计四个菜单,分别是文件、编辑、格式、帮助四个菜单的功能, b) 针对记事本的需求,文件菜单栏实现了新建、打开、保存、另存为、退出的功能。如图二所示。c)8. 图表 2文件菜单栏menuItem0=new JMenuItem5;menuItem1=new JMenuItem7;menuItem2=new JMenuItem2;menuItem3=new JMenuItem1;menuItem4=new JMenuItem1;menuItem00=new JMenuItem("新建(N)");menuItem00.setMnemonic('N');menuItem01=new JMenuItem("打开(O) .");menuItem01.setMnemonic('O');menuItem02=new JMenuItem("保存(S)");menuItem02.setMnemonic('S');menuItem03=new JMenuItem("另存为(A) .");menuItem03.setMnemonic('A'); menuItem04=new JMenuItem("关闭(C)");menuItem04.setMnemonic('C');a) 编辑栏中实现了常见的剪切、复制、粘贴、查找与替换、全选以及时间/日期的功能。如图三所示。b)9. 图表 3编辑菜单栏menuItem10=new JMenuItem("剪切(X)");menuItem10.setMnemonic('X');menuItem11=new JMenuItem("复制(C)");menuItem11.setMnemonic('C');menuItem12=new JMenuItem("粘贴(P)");menuItem12.setMnemonic('P');menuItem13=new JMenuItem("查找(F)");menuItem13.setMnemonic('F');menuItem14=new JMenuItem("替换(R)");menuItem14.setMnemonic('R');menuItem15=new JMenuItem("全选(A)");menuItem15.setMnemonic('A');menuItem16=new JMenuItem("时间/日期(T)");menuItem16.setMnemonic('T');a) 格式栏中实现了自动换行以及字体设置功能。如图四所示b)10. 图表 4格式菜单栏menuItem20=new JCheckBoxMenuItem("自动换行(W)");menuItem20.setMnemonic('T');i. 在字体设置中实现了字体,字号、字形三个功能,如图五所示。11.12.13. 图表 5字体设置选项JTextArea ta;JScrollPane scr;JMenuBar menuBar;JMenu menu;JMenuItem menuItem, popupMenuItem;JPopupMenu popupMenu;JLabel lblStatus;JComboBox cbFont, cbSize, cbStyle;boolean changed;String curFileName;String schText=new String2;String strFonts;String strSize="8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"String strStyle="常规","粗体","斜体","粗斜体"Container ctn;SchInfo schInfo;GraphicsEnvironment ge;Font defaultFont=new Font("宋体", Font.PLAIN, 12), fonts;public zhaoliyang514()super("无标题 - 记事本");changed=false;curFileName=""lblStatus=new JLabel("就绪");ta=new JTextArea();scr=new JScrollPane(ta);ctn=getContentPane();ge=GraphicsEnvironment.getLocalGraphicsEnvironment();strFonts=ge.getAvailableFontFamilyNames();cbFont=new JComboBox(strFonts);cbFont.setFont(defaultFont);cbFont.setSelectedItem("宋体");cbSize=new JComboBox(strSize);cbSize.setFont(defaultFont);cbSize.setSelectedItem("12");cbStyle=new JComboBox(strStyle);cbFont.setSelectedItem("常规");cbStyle.setFont(defaultFont);cbFont.addItemListener(new ItemListener()public void itemStateChanged(ItemEvent ie)int size, style;String fontName;fontName=(String)cbFont.getSelectedItem();style=cbStyle.getSelectedIndex();size=Integer.parseInt(String)cbSize.getSelectedItem();Font font=new Font(fontName, style, size);ta.setFont(font););i. 帮助栏实现了关于记事本的介绍功能,如图六所示。14.15. 图表 6帮助栏选项if (ae.getSource()=menuItem40)JOptionPane.showMessageDialog(null,"基础部,计算B092 赵礼阳","关于 记事本",JOptionPane.INFORMATION_MESSAGE);16. 编辑区设计i. 在编辑区中通过getContentPane().add(new JScrollPane(text)成功实现了将要输入的文本成功输入到编辑区中,并且这句还增加了文本的滚动条,增加了记事本的实用性。2 文件菜单中各项功能的实现ii. 在设计记事本中成功完成了文件栏中的新建、打开、保存、另存为、退出的功能。17.18. 图表 7打开功能public void open()JFileChooser fc=new JFileChooser();if (fc.showOpenDialog(this)=JFileChooser.APPROVE_OPTION)String _curFileName=fc.getSelectedFile().getAbsolutePath();File file=new File(_curFileName);if (file.exists()curFileName=_curFileName;File f=new File(curFileName);setTitle(f.getName()+" - 记事本");changed=false;readFile(file);elseJOptionPane.showMessageDialog(null,file.getAbsolutePath()+"n找不到文件。n请检查所给的文件名是否正确。n","打开失败",JOptionPane.ERROR_MESSAGE);19.20. 图表 8保存及另存为功能public void saveAs()JFileChooser fc=new JFileChooser();fc.setDialogTitle("另存为");if (fc.showSaveDialog(this)=JFileChooser.APPROVE_OPTION)boolean overwrite=false;String _curFileName=fc.getSelectedFile().getAbsolutePath();File file=new File(_curFileName);if (file.exists()int exit;exit=JOptionPane.showConfirmDialog(this,file.getAbsolutePath()+"已存在。n要覆盖它吗? ","另存为",JOptionPane.YES_NO_OPTION);if (exit=JOptionPane.YES_OPTION)overwrite=true;elseoverwrite=true;if (overwrite)changed=false;saveFile(file);curFileName=_curFileName;File f=new File(curFileName);setTitle(f.getName()+" - 记事本");21. 3、格式菜单中各项功能的实现i. 在设计记事本的格式栏中成功完成了自动换行以及字体的设置功能。其中在字体中包括了字体、字号、字形三个设置,达到了对字体设置的基本要求。22. 4、程序源代码import java.io.*;import java.awt.*;import java.awt.event.*;import javax.swing.*;import javax.swing.event.*;import java.util.*;class Searcher extends JDialogprivate JLabel Sample = new JLabel();private int curRow, curCol;private JTextField tfS;private JCheckBox chkCaseSensible;private JButton btnOK;private JButton btnCancel;private Searcher dlg;public static SchInfo schInfo;private JTextArea ta;public Searcher(Frame parent, boolean modal, JTextArea _ta)super(parent,modal);schInfo=new SchInfo();ta=_ta;Container ctn=getContentPane();JPanel ctn1=new JPanel();JPanel ctn2=new JPanel();JPanel ctn3=new JPanel();JPanel ctn4=new JPanel();btnOK=new JButton("查找下一个");btnCancel=new JButton("取消");initAll();chkCaseSensible=new JCheckBox("区分大小写", false);tfS=new JTextField(10);ctn.setLayout(new FlowLayout();ctn.add(ctn1);ctn.add(ctn2);ctn1.setLayout(new GridLayout(2, 1);ctn1.add(ctn3);ctn1.add(ctn4);ctn3.setLayout(new FlowLayout();ctn4.setLayout(new FlowLayout();ctn3.add(new JLabel("查找内容:");ctn3.add(tfS);ctn4.add(chkCaseSensible);ctn2.setLayout(new GridLayout(2, 1);ctn2.add(btnOK);ctn2.add(btnCancel);setTitle("查找");btnOK.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ae)schInfo.str=tfS.getText();schInfo.caseSensible=chkCaseSensible.isSelected();String str=ta.getText();int index;if (schInfo.caseSensible)index=str.indexOf(schInfo.str, ta.getCaretPosition();elseindex=str.toUpperCase().indexOf(schInfo.str.toUpperCase(), ta.getCaretPosition();if (index!=-1)ta.select(index, index+schInfo.str.length();elseJOptionPane.showMessageDialog(null,"找不到""+schInfo.str+""","记事本",JOptionPane.INFORMATION_MESSAGE););btnCancel.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ae)schInfo.str=""schInfo.caseSensible=false;setVisible(false););setVisible(true);private void initAll()setSize(400,140);setLocation(350,150);addWindowListener(new WindowAdapter()public void windowClosing(java.awt.event.WindowEvent e)setVisible (false););class SchInfopublic String str;public boolean caseSensible;class Replacer extends JDialogprivate JLabel Sample = new JLabel();private int curRow, curCol;private JTextField tfS, tfR;private JCheckBox chkCaseSensible;private JButton btnOK, btnReplace;private JButton btnCancel;private Replacer dlg;public static RplInfo schInfo;private JTextArea ta;public Replacer(Frame parent, boolean modal, JTextArea _ta)super(parent,modal);schInfo=new RplInfo();ta=_ta;Container ctn=getContentPane();JPanel ctn1=new JPanel();JPanel ctn2=new JPanel();JPanel ctn3=new JPanel();JPanel ctn4=new JPanel();JPanel ctn5=new JPanel();btnOK=new JButton("查找下一个");btnReplace=new JButton("替换");btnCancel=new JButton("取消");initAll();chkCaseSensible=new JCheckBox("区分大小写", false);tfS=new JTextField(10);tfR=new JTextField(10);ctn.setLayout(new FlowLayout();ctn.add(ctn1);ctn.add(ctn2);ctn1.setLayout(new GridLayout(3,1);ctn1.add(ctn3);ctn1.add(ctn4);ctn1.add(ctn5);ctn3.setLayout(new FlowLayout();ctn4.setLayout(new FlowLayout();ctn5.setLayout(new FlowLayout();ctn3.add(new JLabel("查找内容:");ctn3.add(tfS);ctn4.add(new JLabel("替换为:");ctn4.add(tfR);ctn5.add(chkCaseSensible);ctn2.setLayout(new GridLayout(3, 1);ctn2.add(btnOK);ctn2.add(btnReplace);ctn2.add(btnCancel);setTitle("替换");btnOK.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ae)schInfo.str=tfS.getText();schInfo.caseSensible=chkCaseSensible.isSelected();String str=ta.getText();int index;if (schInfo.caseSensible)index=str.indexOf(schInfo.str, ta.getCaretPosition();elseindex=str.toUpperCase().indexOf(schInfo.str.toUpperCase(), ta.getCaretPosition();if (index!=-1)ta.select(index, index+schInfo.str.length();elseJOptionPane.showMessageDialog(null,"找不到""+schInfo.str+""","记事本",JOptionPane.INFORMATION_MESSAGE););btnReplace.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ae)String str=ta.getSelectedText();int index;schInfo.str=tfS.getText();if (str!=null && str.equals(tfS.getText()index=ta.getCaretPosition()-tfS.getText().length();elseschInfo.caseSensible=chkCaseSensible.isSelected();str=ta.getText();if (schInfo.caseSensible)index=str.indexOf(schInfo.str, ta.getCaretPosition();elseindex=str.toUpperCase().indexOf(schInfo.str.toUpperCase(), ta.getCaretPosition();str=ta.getText();if (index!=-1)str.replaceFirst(tfS.getText(), tfR.getText();String strTemp=str.substring(0, index)+tfR.getText()+str.substring(index+tfS.getText().length(), str.length();str=strTemp;ta.setText(str);ta.setCaretPosition(index+tfR.getText().length();elseJOptionPane.showMessageDialog(null,"找不到""+schInfo.str+""","记事本",JOptionPane.INFORMATION_MESSAGE););btnCancel.addActionListener(new ActionListener()public void actionPerformed(ActionEvent ae)schInfo.str=""schInfo.caseSensible=false;setVisible(false););setVisible(true);private void initAll()setSize(400,140);setLocation(350,150);addWindowListener(new WindowAdapter()public void windowClosing(java.awt.event.WindowEvent e)setVisible (false););class RplInfo extends SchInfopublic String strR;public class zhaoliyang514 extends JFrame implements ActionListenerJTextArea ta;JScrollPane scr;JMenuBar menuBar;JMenu menu;JMenuItem menuItem, popupMenuItem;JPopupMenu popupMenu;JLabel lblStatus;JComboBox cbFont, cbSize, cbStyle;boolean changed;String curFileName;String schText=new String2;String strFonts;String strSize="8","9","10","11","12","14","16","18","20","22","24","26","28","36","48","72"String strStyle="常规","粗体","斜体","粗斜体"Container ctn;SchInfo schInfo;GraphicsEnvironment ge;Font defaultFont=new Font("宋体", Font.PLAIN, 12), fonts;public zhaoliyang514()super("无标题 - 记事本");changed=false;curFileName=""lblStatus=new JLabel("就绪");ta=new JTextArea();scr=new JScrollPane(ta);ctn=getContentPane();ge=GraphicsEnvironment.getLocalGraphicsEnvironment();strFonts=ge.getAvailableFontFamilyNames();cbFont=new JComboBox(strFonts);cbFont.setFont(defaultFont);cbFont.setSelectedItem("宋体");cbSize=new JComboBox(strSize);cbSize.setFont(defaultFont);cbSize.setSelectedItem("12");cbStyle=new JComboBox(strStyle);cbFont.setSelectedItem("常规");cbStyle.setFont(defaultFont);cbFont.addItemListener(new ItemListener()public void itemStateChanged(ItemEvent ie)int size, style;String fontName;fontName=(String)cbFont.getSelectedItem();style=cbStyle.getSelectedIndex();size=Integer.parseInt(String)cbSize.getSelectedItem();Font font=new Font(fontName, style, size);ta.setFont(font););cbSize.addItemListener(new ItemListener()public void itemStateChanged(ItemEvent ie)int size, style;String fontName;fontName=(String)cbFont.getSelectedItem();style=cbStyle.getSelectedIndex();size=Integer.parseInt(String)cbSize.getSelectedItem();Font font=new Font(fontName, style, size);ta.setFont(font););cbStyle.addItemListener(new ItemListener()public void itemStateChanged(ItemEvent ie)int size, style;String fontName;fontName=(String)cbFont.getSelectedItem();style=cbStyle.getSelectedIndex();size=Integer.parseInt(String)cbSize.getSelectedItem();Font font=new Font(fontName, style, size);ta.setFont(font););cbFont.setToolTipText("在这里设置字体");cbSize.setToolTipTex

    注意事项

    本文(《Java程序设计》课程综合性实验报告-简易写字板软件设计.doc)为本站会员(椰子壳)主动上传,三一文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知三一文库(点击联系客服),我们立即给予删除!

    温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载不扣分。




    经营许可证编号:宁ICP备18001539号-1

    三一文库
    收起
    展开