Java课程设计报告敏感词汇分析 .doc

上传人:laozhun 文档编号:2350841 上传时间:2023-02-15 格式:DOC 页数:33 大小:228KB
返回 下载 相关 举报
Java课程设计报告敏感词汇分析 .doc_第1页
第1页 / 共33页
Java课程设计报告敏感词汇分析 .doc_第2页
第2页 / 共33页
Java课程设计报告敏感词汇分析 .doc_第3页
第3页 / 共33页
Java课程设计报告敏感词汇分析 .doc_第4页
第4页 / 共33页
Java课程设计报告敏感词汇分析 .doc_第5页
第5页 / 共33页
点击查看更多>>
资源描述

《Java课程设计报告敏感词汇分析 .doc》由会员分享,可在线阅读,更多相关《Java课程设计报告敏感词汇分析 .doc(33页珍藏版)》请在三一办公上搜索。

1、Java课程设计报告 题 目:敏感词汇分析 年级专业:计科2102 学 号: * 学生姓名: * 指导老师: 完成时间:2010年 6月 20 日目 录摘要1前言21需求分析21.1需求分析21.2功能设计32.概要设计32.1程序设计思路32.2程序运行界面32.3模块说明图42.4程序流程图52.5程序相关说明63.程序详细设计与分析63.1.初始化组件63.2.构建菜单栏及其下拉菜单63.3.“文件”菜单的事件监听73.4.“编辑”菜单的事件监听83.5.异常处理94测试分析105源程序清单136课程设计总结17参考文献17 敏感词汇分析程序的设计摘要 该报告中的程序是使用Java程序编

2、写, 21世纪是信息爆炸的时代,信息技术,网络技术等飞速发展。因而出现许多网络用词,当然也包括不文明的用语,这就需要开发一个软件来检索出分析网络用语,用来屏蔽一些不文明敏感的词汇。给我们大家营造一个安全文明的网络环境!关键字:敏感词汇分析程序;Java语言;Jcreator前言Java的前身是Oak,它一开始只是被应用于消费性电子产品中。后来它的开发者们发现它还可以被用于更大范围的Internet上。1995年,Java语言的名字从Oak编程了Java。1997年J2SE1.1发布。1998年J2SE1.2发布,标志Java2的诞生。十多年来,Java编程语言及平台成功地运用在网络计算及移动等

3、各个领域。Java的体系结构由Java语言、Java class、Java API、Java虚拟机组成。它具有简单、面向对象、健壮、安全、结构中立、可移植和高效能等众多优点。Java支持多线程编程,Java运行时系统在多线程同步方面具有成熟的解决方案。Java的平台标准有Java ME,Java SE和Java EE。Java发展到今天,它的卓越成就及在业界的地位毋庸置疑。目前在众多的支持Java的开发工具中主要的7有Java Development Kit,NetBeans,Jcreator,JBuilder,JDeveloper和Eclipse等。其中Java Development Ki

4、t 简称JDK是大多开发工具的基础。以上的每种开发工具都有优缺点,对于开发者来说,重要的是要根据自己的开发规模、开发内容和软硬件环境等因素来选择一种合适的开发工具。在本程序设计中,因为需要开发的是敏感词汇分析程序,规模较小,内容较少,所以选择了适合初学者使用的JCreator开发工具。1需求分析1.1需求分析现在各大软件公司都有自己的、各种高级敏感词汇的程序,但是这些公司都有自己的版权,我们也不可能得到这些源代码!而且这些公司的程序也相当复杂,仅从日常应用方面来说,对于初学java的我们也无法理解,就需要我们开发一个简单易懂的敏感词汇分析程序。1.2功能设计本程序要构建的文本编辑器程序参照了W

5、indows操作系统的文本编辑器工具,其功能有以下几个方面:(1).菜单中有“文件”,“分析”,“帮助”三个主菜单。(2)“文件”有“新建”“打开”二个子菜单:分别用于新 建文件,打开文件。 (3)“分析”中有“确定”“取消”二个子菜单:用于开始分析文本中的敏感词汇,取消分析文件中含有的敏感词汇。 (4)“帮助”菜单中有关于敏感词汇分析程序的相关介绍。2.概要设计2.1程序设计思路在本程序中,设计了一个菜单栏和文本编辑区。设计过程中用到了FileReader,JMenu,JTextPane,JFileChooser等。JMenu用来制作菜单,菜单包括“文件”“分析”“帮助”。JTextPane

6、主要用来输入文本。2.2程序运行界面2.5程序相关说明整个敏感词汇分析器分为2快:菜单栏和内容输入区。本程序中由Mingan1、TextJMenu、Fenx三个类共同组成分别实现部分程序功能。 3.程序详细设计与分析3.1类Mingan1是输入含有敏感词汇的文本文件并保存在sensitive.txt文件中public class Mingan1 public static void main(String args) Frame f1=new Frame(敏感词分析程序); f1.setBounds(500, 100, 300, 200); f1.setBackground(Color.lig

7、htGray); f1.setLayout(new GridLayout(3,1); Panel p1=new Panel(); f1.add(p1); Panel p2=new Panel(); f1.add(p2); Panel p3=new Panel(); f1.add(p3); f1.setVisible(true); Label l1=new Label(请点击输入含有敏感词的文本文件:); p3.add(l1); Button b1=new Button(确定); p3.add(b1); b1.addActionListener(new ActionListener() publ

8、ic void actionPerformed(ActionEvent e) TestJMenu jmFrame=new TestJMenu(); ); Label l2=new Label(敏感词汇保存在sensitive.txt文件中); p1.add(l2); p2.add(new Label(请查看sensitive.txt文件); 3.2.类TextJMenu继承JFrame实现动作监听(ActionListener)ublic class TestJMenu extends JFrame implements ActionListener3.3构建菜单栏及其下拉菜单TestJMen

9、u() this.setSize(400,300); JMenuBar jmb=new JMenuBar(); JMenu jmFile=new JMenu(文件); JMenuItem jmiNew=new JMenuItem(新建); JMenuItem jmiOpen=new JMenuItem(打开); jmiOpen.addActionListener(this); jmFile.add(jmiNew); jmFile.add(jmiOpen); JMenu jmFenxi=new JMenu(分析); JMenuItem jmiQue=new JMenuItem(确定); JMen

10、uItem jmiQu=new JMenuItem(取消); jmFenxi.add(jmiQue); jmFenxi.add(jmiQu);3.3.“文件”菜单的事件监听jmiQue.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String filterText = jta.getText(); try jta.setText(Fenx.getFilterText(filterText); catch(Exception exx) exx.printStackTrace()

11、; );public void actionPerformed(ActionEvent e) JFileChooser jc=new JFileChooser(); jc.showOpenDialog(this); try File file=jc.getSelectedFile(); FileInputStream fis=new FileInputStream(file); byte buf=new byte10*1024; int len=fis.read(buf); jta.append(new String(buf,0,len); catch(Exception ex) ex.pri

12、ntStackTrace(); 4测试分析图4:点击“文件”运行情况 图5:“文件”菜单中的“打开”对话框图7:“关于”对话框图8:编辑菜单中颜色对话框5源程序清单import java.awt.*;import java.awt.event.*;public class Mingan1 /类一 public static void main(String args) Frame f1=new Frame(敏感词分析程序); f1.setBounds(500, 100, 300, 200); f1.setBackground(Color.lightGray);/背景色 f1.setLayout

13、(new GridLayout(3,1); Panel p1=new Panel(); f1.add(p1); Panel p2=new Panel(); f1.add(p2); Panel p3=new Panel(); f1.add(p3); f1.setVisible(true); Label l1=new Label(请点击输入含有敏感词的文本文件:); p3.add(l1); Button b1=new Button(确定);/定义“确定”按钮 p3.add(b1); b1.addActionListener(new ActionListener() public void acti

14、onPerformed(ActionEvent e) TestJMenu jmFrame=new TestJMenu(); ); Label l2=new Label(敏感词汇保存在sensitive.txt文件中); p1.add(l2); p2.add(new Label(请查看sensitive.txt文件); import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import java.io.File;import java.io.FileInputStre

15、am;public class TestJMenu extends JFrame implements ActionListener JTextArea jta=new JTextArea(); TestJMenu()/构造方法 this.setSize(400,300);/对话框的尺寸 JMenuBar jmb=new JMenuBar();/创建菜单栏 /菜单栏的各个菜单项 JMenu jmFile=new JMenu(文件);/“文件”菜单项的二个下拉菜单 JMenuItem jmiNew=new JMenuItem(新建); JMenuItem jmiOpen=new JMenuIte

16、m(打开); jmiOpen.addActionListener(this); jmFile.add(jmiNew); jmFile.add(jmiOpen); JMenu jmFenxi=new JMenu(分析);/“分析”菜单的二个下拉菜单 JMenuItem jmiQue=new JMenuItem(确定); JMenuItem jmiQu=new JMenuItem(取消); jmFenxi.add(jmiQue); jmFenxi.add(jmiQu); jmiQue.addActionListener(new ActionListener() /添加事件监听 public voi

17、d actionPerformed(ActionEvent e)/监听方法 String filterText = jta.getText(); try jta.setText(Fenx.getFilterText(filterText); catch(Exception exx) exx.printStackTrace(); ); JMenu jmHelp=new JMenu(帮助); jmb.add(jmFile); jmb.add(jmFenxi); jmb.add(jmHelp); this.setJMenuBar(jmb); this.getContentPane().add(jta

18、); this.setVisible(true); public void actionPerformed(ActionEvent e) JFileChooser jc=new JFileChooser(); jc.showOpenDialog(this); try File file=jc.getSelectedFile(); FileInputStream fis=new FileInputStream(file); byte buf=new byte10*1024; int len=fis.read(buf); jta.append(new String(buf,0,len); catc

19、h(Exception ex) ex.printStackTrace(); public static void main(String args) TestJMenu jmFrame=new TestJMenu(); jmFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); import java.io.BufferedReader;import java.io.FileReader;import java.util.ArrayList;import java.util.List;import java.util.regex.Matche

20、r;import java.util.regex.Pattern;public class Fenx public static void main(String args) throws Exception String filterText = new String(); System.out.println(getFilterText(filterText); public static String getFilterText(String filterText) throws Exception List listWord = new ArrayList(); FileReader

21、reader = new FileReader(d:/sensitive.txt); BufferedReader br = new BufferedReader(reader); String s = null; while (s = br.readLine()!= null) listWord.add(s.trim(); br.close(); reader.close(); Matcher m = null; String str1=new String(); for (int i = 0; i listWord.size(); i+) int num=0; Pattern p=Ppil

22、e(listWord.get(i).toString(),Pattern.CASE_INSENSITIVE); StringBuffer sb = new StringBuffer(); m = p.matcher(filterText); while (m.find() m.appendReplacement(sb, 口); num+; str1=n+敏感词 +p.toString()+ 出现:+num+次; /System.out.println(n+敏感词 +p.toString()+ 出现:+num+次); m.appendTail(sb); filterText = sb.toStr

23、ing(); filterText+=str1; return filterText; 6课程设计总结经过差不多两个星期的努力,基本上完成我的Java课程设计敏感词汇分析程序,也基本上实现了我在需求分析时所预期的功能。通过这次的课程设计,使将我从书本上学习到的理论知识用到了实践上,从而进一步巩固和丰富了我所学过的知识,让我更深层次地认识到Java及其强大的功能。同时,做这门课程设计也进一步加强了我的动手能力。为了完成好这次课程设计,我提前做了较多的准备,一边上网查找相关资料,另一方面查阅相关书籍。在这过程中也无形中锻炼了我的思维分析、遇到问题及想方设法通过各种途径解决问题的能力。但是,设计过程

24、中也存在一些问题,本来一开始想给这个敏感词汇分析程序加上一张背景图片,以及添加字体设置功能,但是由于本人知识浅陋以及各种其他原因,使得这些想法没有实现,这是这次课程设计的一点遗憾。参考文献1.孙全党 王吴迪 赵枫朝,Java程序设计应用教程,电子工业出版社,2006.22.雷之宇,Java项目开发实践网络篇,中国铁道出版社,2005.53.赵玉阳,Java从入门到精通,清华大学出版社,2006.84.李茏怡,Java编程实例讲解,高等教育出版社,2005.11完整代码:import java.awt.*;import java.awt.event.*;public class Mingan1

25、public static void main(String args) Frame f1=new Frame(敏感词分析程序); f1.setBounds(500, 100, 300, 200); f1.setBackground(Color.lightGray); f1.setLayout(new GridLayout(3,1); Panel p1=new Panel(); f1.add(p1); Panel p2=new Panel(); f1.add(p2); Panel p3=new Panel(); f1.add(p3); f1.setVisible(true); Label l1

26、=new Label(请点击输入含有敏感词的文本文件:); p3.add(l1); Button b1=new Button(确定); p3.add(b1); b1.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) TestJMenu jmFrame=new TestJMenu(); ); Label l2=new Label(敏感词汇保存在sensitive.txt文件中); p1.add(l2); p2.add(new Label(请查看sensitive.txt文件); im

27、port java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.*;import java.io.File;import java.io.FileInputStream;public class TestJMenu extends JFrame implements ActionListener JTextArea jta=new JTextArea(); TestJMenu() this.setSize(400,300); JMenuBar jmb=new JMenuBar();

28、JMenu jmFile=new JMenu(文件); JMenuItem jmiNew=new JMenuItem(新建); JMenuItem jmiOpen=new JMenuItem(打开); jmiOpen.addActionListener(this); jmFile.add(jmiNew); jmFile.add(jmiOpen); JMenu jmFenxi=new JMenu(分析); JMenuItem jmiQue=new JMenuItem(确定); JMenuItem jmiQu=new JMenuItem(取消); jmFenxi.add(jmiQue); jmFe

29、nxi.add(jmiQu); jmiQue.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) String filterText = jta.getText(); try jta.setText(Fenx.getFilterText(filterText); catch(Exception exx) exx.printStackTrace(); ); JMenu jmHelp=new JMenu(帮助); jmb.add(jmFile); jmb.add(jmFenxi); jm

30、b.add(jmHelp); this.setJMenuBar(jmb); this.getContentPane().add(jta); this.setVisible(true); public void actionPerformed(ActionEvent e) JFileChooser jc=new JFileChooser(); jc.showOpenDialog(this); try File file=jc.getSelectedFile(); FileInputStream fis=new FileInputStream(file); byte buf=new byte10*

31、1024; int len=fis.read(buf); jta.append(new String(buf,0,len); catch(Exception ex) ex.printStackTrace(); public static void main(String args) TestJMenu jmFrame=new TestJMenu(); jmFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); import java.io.BufferedReader;import java.io.FileReader;import java

32、.util.ArrayList;import java.util.List;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Fenx public static void main(String args) throws Exception String filterText = new String(); System.out.println(getFilterText(filterText); public static String getFilterText(String filter

33、Text) throws Exception List listWord = new ArrayList(); FileReader reader = new FileReader(d:/sensitive.txt); BufferedReader br = new BufferedReader(reader); String s = null; while (s = br.readLine()!= null) listWord.add(s.trim(); br.close(); reader.close(); Matcher m = null; String str1=new String(); for (int i = 0; i listWord.size(); i+) int num=0; Pattern p=Ppile(listWord.get(i).toString(),Pattern.CASE_INSENSITIVE); StringBuffer sb = new StringBuffer(); m = p.matcher(filterText); while (m.find() m.appendReplacement(sb, 口); num+; str1=n+敏感词 +p.toString()+ 出现:+num+次;

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

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


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号