资源描述
广西大学课程设计报告课程: 数据结构题目:简易英汉词典系统学 院:_计算机与电子信息学院_ 专 业:_计网类_ 班 级:_计网071_ _ _ 学 号: 0 学生姓名: 指导教师:_ _ 二九 年 四 月一、实验目的和要求【实验目的】设计一个简易英汉词典系统,实现基本的单词检索功能,即输入英文单词则系统输出其汉语,反之亦然;并能够进行基本的词典维护操作,包括插入和删除,要求按英语的词典顺序排列单词。【设计要求】(1)使用图形化界面。(2)建立英语词汇表,输入为小写字母时为合法输入。(3)每个词条应包含单词的英语形式、汉语释义、发音等基本信息。二、设计概要:1、根据实验要求,与及所了解的数据类型相关知识,定义了如下数据类型:链接数据库声明的变量:Connection connection = null;Statement statement = null;ResultSet Result = null;声明全局变量:String newWord, pronunciations, indexWord=, deleteWord, searchEnglish, searchChinese,isSound;它们分别是:新增单词、新单词音标、引擎词、删除词、查找的英文、查找的汉语、判断音频是否存在。2、实验功能所定义的各种按钮、文本框、选择框和列表框:取消删除功能按钮:JButton deleteCancelButton = new JButton();英汉互译面板上的发音按钮:JButton sound = new JButton();浏览词库面板上的发音按钮:JButton scanSoundButton = new JButton();添加单词的按钮:JButton addOkJButton = new JButton();取消添加功能的按钮:JButton addCancelButton = new JButton();删除词库单词信息按钮:JButton deleteOkButton = new JButton();浏览词库按钮:JButton scanButton = new JButton();要查找的英文或汉语的文本框输入框:JTextField inputSearchWord = new JTextField();新增单词文本输入框:JTextField inputNewWord = new JTextField();新增单词音标输入框:JTextField pronunciation = new JTextField();新增单词释义输入框:JTextField newWordChinese = new JTextField();新增单词过去式输入框:JTextField newWordPreterite = new JTextField();新增单词现在进行时态输入框:JTextField newWordModernism = new JTextField();要删除的单词输入框:JTextField inputDeleteWord = new JTextField();新增单词词性复选框:JComboBox newWordClass = new JComboBox();列出要查找的词的记录信息的多行文本框:TextArea outputSearchEnglish = new TextArea();列出要删除的单词的记录信息的多行文本框:TextArea deleteWordChinese = new TextArea();列出浏览时需浏览单词信息的多行文本框: TextArea scanOutput = new TextArea();DefaultListModel model = new DefaultListModel(); 列出所查找的英文或汉语对应的单词的列表框:JList listSearchEnglish = new JList(model);列出备选英标的列表框:JList pronunciationJList = new JList(listItem);列出可能且可以被删除的单词的列表框:JList deleteJList = new JList(model);列出词库所有单词的列表框: JList scanWordJList = new JList(model);3、实现功能所定义的各种函数:1)public static String Return(String str) 将数据库里的单词的音标进行还原。因为有些音标不能正确存入数据库,只能以其它字符代替,读取时再还原。2)public void Play(String word) 播放单词word的音频。3)public void inputSearch_caretUpdate(CaretEvent e) 当inputSearch(注:要查找的词)输入框值改变时,listSearchEnglish(注:列出查找结果)列表框和outputSearchEnglish(注:写出单词信息)文本输出框被清空,取inputSearch输入框值赋给indexWord,如果indexWord不为空,连接数据库;再判断要查找的是英语,还是汉语,根据判断结果进行查找,并将结果集按升序排列,输出到listSearchEnglish列表框4)public void listSearchEnglish_mouseClicked(MouseEvent me) 当鼠标单击listSearchEnglish列表框时,取所选选项的值赋给变量searchEnglish,去掉其两端空格,outputSearchEnglish文本输出框被清空,发音按钮变成灰白色,从数据库读取要查找的单词,将其音标进行还原,将单词信息输出到outputSearchEnglish文本框,如果可以发音,发音按钮变红色,否则indexWord被赋给空值5)public void sound_actionPerformed(ActionEvent e) 如果查找单词有音频且查找词不为空,则可发音,否则按钮变为灰白色6)public void inputNewWord_caretUpdate(CaretEvent e) 一旦输入的新单词字母不是小写字母或空格时,弹出提示框7)public void pronunciation_caretUpdate(CaretEvent e) 对输入的音标进行处理,因为字符u0254、u01DD、u00E6 存入数据库时会变成?或出错,所以用0、1、2、4分别代替他们,读取时通过调用Return函数还原,且将音标两端和中间空格去掉8)public void pronunciationJList_mouseClicked(MouseEvent me) 当在音标选项列表单击鼠标选择音标时,将所选音标输入音标输入框9)public void addOkJButton_actionPerformed(ActionEvent e) 读取未读取的输入框的字符,去掉单词、注释各自两端空格,并将去掉它们各自中间两个或两个以上的空格留一个空格,接着在数据库查找添加的单词是否已存在,若已存在,弹出提示框,不能再添加,否则向数据库添加新单词信息,最后清空所有输入框10)public void addCancelButton_actionPerformed(ActionEvent e)点击添加取消按钮,新增面板所有输入框被清空11)public void inputDeleteWord_caretUpdate(CaretEvent e)当inputDeleteWord输入框值改变时,清空deleteJList列表框,读取inputDeleteWord输入框值赋给变量deleteWord,按模糊查找法查找以deleteWord的值开头的所有单词,按升序排列,并将他们输出到deleteJList列表框12)public void deleteJList_mouseClicked(MouseEvent me) 当在deleteJList列表框单击选项时,读取选项值赋给deleteWord变量,并去掉其两端空格,向inputDeleteWord输入框输入deleteWord变量值,接着从数据库读取要删除的单词的信息,如某属性不为空,将其输入到eleteWordChinese多行文本框13)public void deleteOkButton_actionPerformed(ActionEvent e) 单击删除按钮,如果输入框为空,则弹出提示框,否则从数据库中删除要删除的单词的所有记录14)Public void deleteCancelButton_actionPerformed(ActionEvent e) 单击取消按钮,inputDeleteWord、deleteWordChinese都被清空15)public void scanButton_actionPerformed(ActionEvent e) 单击浏览按钮,scanWordJList列表框被清空,然后从数据库读取所有单词,按升序排列;然后将所得结果集输入到scanWordJList列表框16)public void scanWordJList_mouseClicked(MouseEvent me) 当鼠标单击scanWordJList列表框时,取所选选项的值赋给变量ndexWord,去掉其两端空格,scanOutput文本框被清空,发音按钮变成灰白色,从数据库读取要查找的单词(indexWord的值),将其音标进行还原,将单词信息输出到scanOutput文本框,如果可以发音,发音按钮变红色,否则indexWord被赋给空值17)public void soundButton_actionPerformed(ActionEvent e) 如果查找单词有音频且查找词不为空,则可发音,否则按钮变为灰白色三、程序模块流程图开始英汉互译是否输入?是否是英文查找英文查找汉译列出找到的单词单击?列出单词信息清空列表框和多行文本框是否找到显错错误添加词汇输入单词?是否合法弹出提示信息是否选择备选音标写入音标输入框单击添加按钮输入单词?弹出警告成功?显示错误提示成功单击取消按钮清空所有输入框是否已存在保存所有信息不能添加可否发音结束发音按钮变红结束YNYYNYYNNYNYYYNY单击发音删除词汇输入?模糊查找是否匹配列出找到的单词单击选择?列出单词信息并把单词写入输入框点击删除按钮是否有单词弹出提示信息删除该单词点击取消按钮清空各框内内容浏览词库按升序列出词库单词是否被单击列出单词信息可否发音发音按钮变红单击浏览按钮发音按钮是否红结束结束YNYNYYNNYYNY单击发音四、具体程序设计代码package languanhengdictionary;import java.awt.BorderLayout;import java.sql.*;import java.io.File;import java.io.IOException;import javax.sound.sampled.AudioSystem;import javax.sound.sampled.LineUnavailableException;import javax.sound.sampled.UnsupportedAudioFileException;import javax.sound.sampled.AudioInputStream;import javax.sound.sampled.AudioFormat;import javax.sound.sampled.SourceDataLine;import javax.sound.sampled.DataLine;import javax.swing.JFrame;import javax.swing.JTabbedPane;import java.awt.Rectangle;import javax.swing.JPanel;import javax.swing.JLabel;import java.awt.Font;import java.awt.Color;import javax.swing.JTextField;import javax.swing.JButton;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JTextArea;import java.awt.TextArea;import java.awt.Dimension;import java.awt.Choice;import java.awt.event.ItemEvent;import java.awt.event.ItemListener;import java.awt.Checkbox;import javax.swing.JComboBox;import javax.swing.JList;import javax.swing.JOptionPane;import java.awt.*;import javax.swing.JScrollPane;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import javax.swing.DefaultListModel;import java.awt.event.HierarchyListener;import java.awt.event.HierarchyEvent;import javax.swing.event.CaretListener;import javax.swing.event.CaretEvent;import javax.swing.border.TitledBorder;import javax.swing.UIManager;import javax.swing.BorderFactory;import java.io.*;import javax.swing.border.Border;public class englishFrame extends JFrame Connection connection = null; Statement statement = null; ResultSet Result = null; public englishFrame() try jbInit(); catch (Exception exception) exception.printStackTrace(); private void jbInit() throws Exception getContentPane().setLayout(null); mainJP.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); mainJP.setForeground(new Color(0, 242, 118); mainJP.setBorder(titledBorder1); mainJP.setToolTipText(); mainJP.setBounds(new Rectangle(2, 51, 543, 295); searchEnglishOrChineseJP.setLayout(null); addWordJP.setLayout(null); deleteJP.setLayout(null); scanStock.setLayout(null); jLabel2.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); jLabel2.setForeground(new Color(0, 180, 62); jLabel2.setText(输入引擎词); jLabel2.setBounds(new Rectangle(8, 16, 106, 43); inputSearchWord.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); jScrollPane1.setBounds(new Rectangle(118, 60, 145, 178); listSearchEnglish.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); listSearchEnglish.setForeground(Color.blue); listSearchEnglish.setSelectionBackground(new Color(51, 255, 104); outputSearchEnglish.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); outputSearchEnglish.setBounds(new Rectangle(267, 59, 227, 179); jLabel4.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); jLabel4.setForeground(new Color(0, 180, 0); jLabel4.setText(新单词); jLabel4.setBounds(new Rectangle(6, 9, 81, 34); inputNewWord.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); inputNewWord.setBounds(new Rectangle(93, 11, 155, 34); jLabel5.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); jLabel5.setForeground(new Color(0, 159, 14); jLabel5.setText(发 音); jLabel5.setBounds(new Rectangle(6, 118, 76, 33); jLabel6.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); jLabel6.setForeground(new Color(0, 173, 55); jLabel6.setText(词 性); jLabel6.setBounds(new Rectangle(7, 63, 81, 35); pronunciation.setFont(new java.awt.Font(Arial Unicode MS, Font.PLAIN,20); pronunciation.setBounds(new Rectangle(92, 119, 154, 36); newWordClass.setBounds(new Rectangle(95, 62, 154, 36); jScrollPane3.setBounds(new Rectangle(93, 156, 154, 79); jLabel7.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); jLabel7.setForeground(new Color(0, 208, 48); jLabel7.setText(注 释); jLabel7.setBounds(new Rectangle(267, 9, 72, 34); newWordChinese.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); newWordChinese.setBounds(new Rectangle(354, 11, 164, 34); jLabel8.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); jLabel8.setForeground(new Color(0, 187, 0); jLabel8.setToolTipText(); jLabel8.setText(过去式); jLabel8.setBounds(new Rectangle(264, 62, 77, 32); newWordPreterite.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); newWordPreterite.setBounds(new Rectangle(353, 61, 164, 36); jLabel9.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); jLabel9.setForeground(new Color(0, 187, 21); jLabel9.setText(现代式); jLabel9.setBounds(new Rectangle(263, 122, 75, 31); newWordModernism.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); newWordModernism.setBounds(new Rectangle(353, 121, 163, 37); addOkJButton.setBounds(new Rectangle(261, 179, 83, 40); addOkJButton.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); addOkJButton.setText(确定); addCancelButton.setBounds(new Rectangle(407, 182, 83, 37); addCancelButton.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); addCancelButton.setText(取消); jLabel10.setFont(new java.awt.Font(宋体, Font.PLAIN, 25); jLabel10.setForeground(new Color(0, 187, 62); jLabel10.setText(输入词汇); jLabel10.setBounds(new Rectangle(6, 33, 107, 34); inputDeleteWord.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); inputDeleteWord.setBounds(new Rectangle(112, 31, 186, 37); deleteWordChinese.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); deleteWordChinese.setBounds(new Rectangle(112, 69, 185, 168); jScrollPane4.setBounds(new Rectangle(297, 31, 139, 206); deleteJList.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); deleteJList.setForeground(Color.blue); deleteJList.setSelectionBackground(new Color(51, 255, 0); deleteOkButton.setBounds(new Rectangle(437, 31, 83, 38); deleteOkButton.setFont(new java.awt.Font(楷体, Font.PLAIN, 20); deleteOkButton.setForeground(new Color(0, 187, 55); deleteOkButton.setText(删除); scanButton.setForeground(new Color(0, 214, 0); scanButton.setText(浏览); jScrollPane5.setBounds(new Rectangle(25, 59, 146, 178); scanOutput.setColumns(5); scanOutput.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); scanOutput.setBounds(new Rectangle(188, 60, 315, 177); scanWordJList.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); scanWordJList.setForeground(Color.blue); scanWordJList.setSelectionBackground(Color.green); jLabel11.setFont(new java.awt.Font(楷体, Font.PLAIN, 45); jLabel11.setForeground(new Color(0, 255, 138); jLabel11.setText(欢迎访问词库); jLabel11.setBounds(new Rectangle(197, 8, 287, 40); deleteCancelButton.setBounds(new Rectangle(437, 96, 83, 34); deleteCancelButton.setFont(new java.awt.Font(楷体, Font.PLAIN, 20); deleteCancelButton.setForeground(new Color(0, 221, 42); deleteCancelButton.setToolTipText(); deleteCancelButton.setText(取消); pronunciationJList.setSelectionBackground(new Color(51, 255, 125); sound.setBounds(new Rectangle(420, 24, 74, 33); sound.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); sound.setToolTipText(); sound.setText(发音); inputSearchWord.setBounds(new Rectangle(117, 24, 302, 35); scanButton.setBackground(new Color(240, 240, 240); scanButton.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); scanSoundButton.setBounds(new Rectangle(110, 15, 79, 37); scanSoundButton.setFont(new java.awt.Font(宋体, Font.PLAIN, 20); scanSoundButton.setText(发音); scanButton.setBounds(new Rectangle(27, 14, 78, 38); this.getContentPane().add(mainJP); searchEnglishOrChineseJP.add(jLabel2); searchEnglishOrChineseJP.add(jScrollPane1); searchEnglishOrChineseJP.add(outputSearchEnglish); searchEnglishOrChineseJP.add(inputSearchWord); searchEnglishOrChineseJP.add(sound); jScrollPane1.getViewport().add(listSearchEnglish); mainJP.add(searchEnglishOrChineseJP, 英汉互译); mainJP.add(addWordJP, 添加词汇); addWordJP.add(jLabel4); addWordJP.add(inputNewWord); addWordJP.add(jLabel7); addWordJP.add(newWordChinese); addWordJP.add(newWordClass); addWordJP.add(jLabel6); addWordJP.add(newWordPreterite); addWordJP.add(jLabel5); addWordJP.add(jLabel9); addWordJP.add(newWordModernism); addWordJP.add(jScrollPane3); addWordJP.add(pronunciation); addWordJP.add(addOkJButton); addWordJP.add(addCancelButton); addWordJP.add(jLabel8); jScrollPane3.getViewport().add(pronunciationJList); mainJP.add(deleteJP, 删除词汇); deleteJP.add(jLabel10); deleteJP.add(inputDeleteWord); deleteJP.add(deleteWordChinese); deleteJP.add(jScrollPane4); deleteJP.add(deleteOkButton); deleteJP.add(deleteCancelButton); jScrollPane4.getViewport().add(deleteJList); mainJP.add(scanStock, 浏览词库); scanStock.add(jScrollPane5); jScrollPane5.getViewport().add(scanWordJList); scanStock.add(scanButton); scanStock.add(scanOutput); scanStock.add(jLabel11); scanStock.add(scanSoundButton); this.getContentPane().add(jLabel1); jLabel1.setFont(new java.awt.Font(楷体, Font.PLAIN, 45); jLabel1.setForeground(Color.blue); jLabel1.setText(蓝氏简易英汉词典); jLabel1.setBounds(new Rectangle(107, 5, 374, 47); newWordClass.addItem(n. 名词); newWordClass.addItem(adj. 形容词); newWordClass.addItem(adv. 副词); newWordClass.addItem(num. 量词); newWordClass.addItem(V. 动词); newWordClass.addItem(Vi. 不及物动词); newWordClass.addItem(Vt. 及物动词); newWordClass.addItem(短语); pronunciationJList.setLayoutOrientation(pronunciationJList.HORIZONTAL_WRAP); this.setSize(new Dimension(560, 385); /第一个参/为长度,第二个参数为高度/-英汉互译模块函数调用-/ /发音按钮监听器 sound.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) sound_actionPerformed(e); ); /查找输入框监听器 inputSearchWord.addCaretListener(new CaretListener() public void caretUpdate(CaretEvent e) inputSearch_caretUpdate(e); ); /查找单词列表监听器 listSearchEnglish.addMouseListener(new MouseAdapter() public void mouseClicked(MouseEvent e) listSearchEnglish_mouseClicked(e); );/-添加面板模块函数调-/ /新单词输入框监听器 inputNewWord.addCaretListener(new CaretListener() public void caretUpdate(CaretEvent e) inputNewWord_caretUpdate(e); ); /新单词音标输入框监听器 pronunciation.addCaretListener(new CaretListener() public void caretUpdate(CaretEvent e) pronunciation_caretUpdate(e); ); /音标选择列表鼠标监听器 pronunciationJList.addMouseListener(new MouseAdapter() public void mouseClicked(MouseEvent e) pronunciationJList_mouseClicked(e); ); /添加按钮监听器 addOkJButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) addOkJButton_actionPerformed(e); ); / 取消添加单词按钮监听器 addCancelButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) addCancelButton_actionPerformed(e); ); /-删除模块函数调用-/ /删除单词输入框监听器 inputDeleteWord.addCaretListener(new CaretListener() public void caretUpdate(CaretEvent e) inputDeleteWord_caretUpdate(e); ); /删除单词列表框鼠标监听器 deleteJList.addMouseListener(new MouseAdapter() public void mouseClicked(MouseEvent e) deleteJList_mouseClicked(e); ); /删除按钮监听器 deleteOkButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) deleteOkButton_actionPerformed(e); ); /取消删除按钮监听器 deleteCancelButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) deleteCancelButton_actionPerformed(e); );/-浏览数据库函数调用-/ /浏览词库单词发音按钮监听器 scanSoundButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) soundButton_actionPerformed(e); ); /浏览词库按钮监听器 scanButton.addActionListener(new ActionListener() public void actionPerformed(ActionEvent e) scanButton_actionPerformed(e); );/浏览单词列表鼠标监听器 scanWordJList.addMouseListener(new MouseAdapter() public void mouseClicked(MouseEvent e) scanWordJList_mouseClicked(e); ); String listItem = /, , , b,c, d, e,f, h, g, i:, i, j, k,l,m, n,:,p, r, s, t,u, u:,ju:,v,w, z, , , , ,u00F0,u0259, u0259u,u0254:,u0254, u00E6, , :, ai, ei, tr, dr, au, ts, dz, d3, t, , ; DefaultListModel model = new DefaultListModel(); JTabbedPane mainJP = new JTabbedPane(); JLabel jLabel1 = new JLabel(); JPanel searchEnglishOrChineseJP = new JPanel(); JPanel addWordJP = new JPanel(); JPanel deleteJP = new JPanel(); JPanel scanStock = new JPanel(); JLabel jLabel2 = new JLabel(); JTextField inputSearchWord = new JTextField(); JScrollPane jScrollPane1 = new JScrollPane(); JList listSearchEnglish = new JList(model); TextArea outputSearchEnglish = new TextArea(); JLabel jLabel4 = new
展开阅读全文