版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
..課程設(shè)計報告課程:《數(shù)據(jù)結(jié)構(gòu)》題目:簡易英漢詞典系統(tǒng)學院:專業(yè):計網(wǎng)類班級:計網(wǎng)071學號:03學生姓名:指導(dǎo)教師:一、 實驗?zāi)康暮鸵蟆緦嶒災(zāi)康摹吭O(shè)計一個簡易英漢詞典系統(tǒng),實現(xiàn)基本的單詞檢索功能,即輸入英文單詞則系統(tǒng)輸出其漢語,反之亦然;并能夠進行基本的詞典維護操作,包括插入和刪除,要求按英語的詞典順序排列單詞。【設(shè)計要求】使用圖形化界面。建立英語詞匯表,輸入為小寫字母時為合法輸入。每個詞條應(yīng)包含單詞的英語形式、漢語釋義、發(fā)音等基本信息。二、 設(shè)計概要:1、根據(jù)實驗要求,與及所了解的數(shù)據(jù)類型相關(guān)知識,定義了如下數(shù)據(jù)類型:鏈接數(shù)據(jù)庫聲明的變量:Connectionconnection=null;Statementstatement=null;ResultSetResult=null;聲明全局變量:StringnewWord,pronunciations,indexWord="",deleteWord,searchEnglish,searchChinese,isSound;它們分別是:新增單詞、新單詞音標、引擎詞、刪除詞、查找的英文、查找的漢語、判斷音頻是否存在。2、實驗功能所定義的各種按鈕、文本框、選擇框和列表框:取消刪除功能按鈕:JButtondeleteCancelButton=newJButton();英漢互譯面板上的發(fā)音按鈕:JButtonsound=newJButton();瀏覽詞庫面板上的發(fā)音按鈕:JButtonscanSoundButton=newJButton();添加單詞的按鈕:JButtonaddOkJButton=newJButton();取消添加功能的按鈕:JButtonaddCancelButton=newJButton();刪除詞庫單詞信息按鈕:JButtondeleteOkButton=newJButton();瀏覽詞庫按鈕:JButtonscanButton=newJButton();要查找的英文或漢語的文本框輸入框:JTextFieldinputSearchWord=newJTextField();新增單詞文本輸入框:JTextFieldinputNewWord=newJTextField();新增單詞音標輸入框:JTextFieldpronunciation=newJTextField();新增單詞釋義輸入框:JTextFieldnewWordChinese=newJTextField();新增單詞過去式輸入框:JTextFieldnewWordPreterite=newJTextField();新增單詞現(xiàn)在進行時態(tài)輸入框:JTextFieldnewWordModernism=newJTextField();要刪除的單詞輸入框:JTextFieldinputDeleteWord=newJTextField();新增單詞詞性復(fù)選框:JComboBoxnewWordClass=newJComboBox();列出要查找的詞的記錄信息的多行文本框:TextAreaoutputSearchEnglish=newTextArea();列出要刪除的單詞的記錄信息的多行文本框:TextAreadeleteWordChinese=newTextArea();列出瀏覽時需瀏覽單詞信息的多行文本框:TextAreascanOutput=newTextArea();DefaultListModelmodel=newDefaultListModel();列出所查找的英文或漢語對應(yīng)的單詞的列表框:JListlistSearchEnglish=newJList(model);列出備選英標的列表框:JListpronunciationJList=newJList(listItem);列出可能且可以被刪除的單詞的列表框:JListdeleteJList=newJList(model);列出詞庫所有單詞的列表框:JListscanWordJList=newJList(model);3、實現(xiàn)功能所定義的各種函數(shù):publicstaticStringReturn(Stringstr)將數(shù)據(jù)庫里的單詞的音標進行還原。因為有些音標不能正確存入數(shù)據(jù)庫,只能以其它字符代替,讀取時再還原。publicvoidPlay(Stringword)播放單詞word的音頻。publicvoidinputSearch_caretUpdate(CaretEvente)當inputSearch(注:要查找的詞)輸入框值改變時,listSearchEnglish(注:列出查找結(jié)果)列表框和outputSearchEnglish(注:寫出單詞信息)文本輸出框被清空,取inputSearch輸入框值賦給indexWord,如果indexWord不為空,連接數(shù)據(jù)庫;再判斷要查找的是英語,還是漢語,根據(jù)判斷結(jié)果進行查找,并將結(jié)果集按升序排列,輸出到listSearchEnglish列表框publicvoidlistSearchEnglish_mouseClicked(MouseEventme)當鼠標單擊listSearchEnglish列表框時,取所選選項的值賦給變量searchEnglish,去掉其兩端空格,outputSearchEnglish文本輸出框被清空,發(fā)音按鈕變成灰白色,從數(shù)據(jù)庫讀取要查找的單詞,將其音標進行還原,將單詞信息輸出到outputSearchEnglish文本框,如果可以發(fā)音,發(fā)音按鈕變紅色,否則indexWord被賦給空值publicvoidsound_actionPerformed(ActionEvente)如果查找單詞有音頻且查找詞不為空,則可發(fā)音,否則按鈕變?yōu)榛野咨玴ublicvoidinputNewWord_caretUpdate(CaretEvente)一旦輸入的新單詞字母不是小寫字母或空格時,彈出提示框publicvoidpronunciation_caretUpdate(CaretEvente)對輸入的音標進行處理,因為字符\u0254、\u01DD、‘、\u00E6存入數(shù)據(jù)庫時會變成?或出錯,所以用0、1、2、4分別代替他們,讀取時通過調(diào)用Return函數(shù)還原,且將音標兩端和中間空格去掉publicvoidpronunciationJList_mouseClicked(MouseEventme)當在音標選項列表單擊鼠標選擇音標時,將所選音標輸入音標輸入框publicvoidaddOkJButton_actionPerformed(ActionEvente)讀取未讀取的輸入框的字符,去掉單詞、注釋各自兩端空格,并將去掉它們各自中間兩個或兩個以上的空格留一個空格,接著在數(shù)據(jù)庫查找添加的單詞是否已存在,若已存在,彈出提示框,不能再添加,否則向數(shù)據(jù)庫添加新單詞信息,最后清空所有輸入框publicvoidaddCancelButton_actionPerformed(ActionEvente)點擊添加取消按鈕,新增面板所有輸入框被清空publicvoidinputDeleteWord_caretUpdate(CaretEvente)當inputDeleteWord輸入框值改變時,清空deleteJList列表框,讀取inputDeleteWord輸入框值賦給變量deleteWord,按模糊查找法查找以deleteWord的值開頭的所有單詞,按升序排列,并將他們輸出到deleteJList列表框publicvoiddeleteJList_mouseClicked(MouseEventme)當在deleteJList列表框單擊選項時,讀取選項值賦給deleteWord變量,并去掉其兩端空格,向inputDeleteWord輸入框輸入deleteWord變量值,接著從數(shù)據(jù)庫讀取要刪除的單詞的信息,如某屬性不為空,將其輸入到eleteWordChinese多行文本框publicvoiddeleteOkButton_actionPerformed(ActionEvent e)單擊刪除按鈕,如果輸入框為空,則彈出提示框,否則從數(shù)據(jù)庫中刪除要刪除的單詞的所有記錄PublicvoiddeleteCancelButton_actionPerformed(ActionEvente)單擊取消按鈕,inputDeleteWord、deleteWordChinese都被清空publicvoidscanButton_actionPerformed(ActionEvente)單擊瀏覽按鈕,scanWordJList列表框被清空,然后從數(shù)據(jù)庫讀取所有單詞,按升序排列;然后將所得結(jié)果集輸入到scanWordJList列表框publicvoidscanWordJList_mouseClicked(MouseEventme)當鼠標單擊scanWordJList列表框時,取所選選項的值賦給變量ndexWorc,去掉其兩端空格,seanOutput文本框被清空,發(fā)音按鈕變成灰白色,從數(shù)據(jù)庫讀取要查找的單詞(indexWord的值),將其音標進行還原,將單詞信息輸出到seanOutput文本框,如果可以發(fā)音,發(fā)音按鈕變紅色,否則indexWord被賦給空值publievoidsoundButton_aetionPerformed(AetionEvente)如果查找單詞有音頻且查找詞不為空,則可發(fā)音,否則按鈕變?yōu)榛野咨?、程序模塊流程圖文檔來源為文檔來源為:從網(wǎng)絡(luò)收集整理.word版本可編輯.歡迎下載支持.輸入單詞?開始N可否發(fā)音是否輸入?英漢互譯Y列出單詞信息Y是否是英文YNYN單擊?結(jié)束NY列出找到的單詞是否找到顯錯錯誤Y是否合法輸入單詞?N彈出提示信息Y寫入音標輸入框添加詞匯單擊添加按鈕Y保存所有信息是否已存在成功?不能添加YN提示成功顯示錯誤結(jié)束清空列表框和多行文本框是否選擇備選音標Y彈出警告發(fā)音按鈕變紅單擊發(fā)音查找英文查找漢譯Y輸入?模糊查找YN列出找到的單詞是否匹配N結(jié)束單擊選擇?YN點擊刪除按鈕是否有單詞Y刪除該單詞清空各框內(nèi)內(nèi)容點擊取消按鈕單擊瀏覽按鈕按升序列出詞庫單詞Y列出單詞信息是否被單擊NN可否發(fā)音結(jié)束YY列出單詞信息并把單詞寫入輸入框發(fā)音按鈕是否紅發(fā)音按鈕變紅單擊發(fā)音彈出提示信息四、具體程序設(shè)計代碼packagelanguanhengdictionary;import;importjava.sql.*;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;import;importjava.awt.*;import;import;import;import;import;import;import;import;import;import;import;importjava.io.*;import;publicclassenglishFrameextendsJFrame{Connectionconnection=null;Statementstatement=null;ResultSetResult=null;publicenglishFrame(){try{jbInit();}catch(Exceptionexception){exception.printStackTrace();}}privatevoidjbInit()throwsException{getContentPane().setLayout(null);mainJP.setFont(new" 宋體",Font.PLAIN,25));mainJP.setForeground(newColor(0,242,118));mainJP.setBorder(titledBorder1);mainJP.setToolTipText("");mainJP.setBounds(newRectangle(2,51,543,295));searchEnglishOrChineseJP.setLayout(null);addWordJP.setLayout(null);deleteJP.setLayout(null);scanStock.setLayout(null);jLabel2.setFont(new"宋體",Font.PLAIN,20));jLabel2.setForeground(newColor(0,180,62));jLabel2.setText("輸入引擎詞");jLabel2.setBounds(newRectangle(8,16,106,43));inputSearchWord.setFont(new" 宋體",Font.PLAIN,20));jScrollPane1.setBounds(newRectangle(118,60,145,178));listSearchEnglish.setFont(new" 宋體",Font.PLAIN,20));listSearchEnglish.setForeground(Color.blue);listSearchEnglish.setSelectionBackground(newColor(51,255,104));outputSearchEnglish.setFont(new" 宋體",Font.PLAIN,20));outputSearchEnglish.setBounds(new Rectangle(267,59,227,179));jLabel4.setFont(new" 宋體",Font.PLAIN,25));jLabel4.setForeground(newColor(0,180,0));jLabel4.setText("新單詞");jLabel4.setBounds(newRectangle(6,9,81,34));inputNewWord.setFont(new"宋體",Font.PLAIN,20));inputNewWord.setBounds(newRectangle(93,11,155,34));jLabel5.setFont(new" 宋體",Font.PLAIN,25));jLabel5.setForeground(newColor(0,159,14));jLabel5.setText("發(fā)音");jLabel5.setBounds(newRectangle(6,118,76,33));jLabel6.setFont(new" 宋體",Font.PLAIN,25));jLabel6.setForeground(newColor(0,173,55));jLabel6.setText("詞性");jLabel6.setBounds(newRectangle(7,63,81,35));pronunciation.setFont(new"ArialUnicodeMS",Font.PLAIN,20));pronunciation.setBounds(newRectangle(92,119,154,);newWordClass.setBounds(newRectangle(95,62,154,36));jScrollPane3.setBounds(newRectangle(93,156,154,79));jLabel7.setFont(new" 宋體",Font.PLAIN,25));jLabel7.setForeground(newColor(0,208,48));jLabel7.setText("注釋");jLabel7.setBounds(newRectangle(267,9,72,34));newWordChinese.setFont(new" 宋體",Font.PLAIN,20));newWordChinese.setBounds(newRectangle(354,11,164,34));jLabel8.setFont(new"宋體",Font.PLAIN,25));jLabel8.setForeground(newColor(0,187,0));jLabel8.setToolTipText("");jLabel8.setText("過去式");jLabel8.setBounds(newRectangle(264,62,77,32));newWordPreterite.setFont(new" 宋體",Font.PLAIN,20));newWordPreterite.setBounds(newRectangle(353,61,164,36));jLabel9.setFont(new"宋體",Font.PLAIN,25));jLabel9.setForeground(newColor(0,187,21));jLabel9.setText("現(xiàn)代式");jLabel9.setBounds(newRectangle(263,122,75,31));newWordModernism.setFont(new" 宋體",Font.PLAIN,20));newWordModernism.setBounds(newRectangle(353,121,163,37));addOkJButton.setBounds(newRectangle(261,179,83,40));addOkJButton.setFont(new" 宋體",Font.PLAIN,20));addOkJButton.setText(" 確定");addCancelButton.setBounds(newRectangle(407,182,83,);addCancelButton.setFont(new" 宋體",Font.PLAIN,20));addCancelButton.setText("取消");jLabel10.setFont(new" 宋體",Font.PLAIN,25));jLabel10.setForeground(newColor(0,187,62));jLabel10.setText("輸入詞匯");jLabel10.setBounds(newRectangle(6,33,107,34));inputDeleteWord.setFont(new" 宋體",Font.PLAIN,20));inputDeleteWord.setBounds(newRectangle(112,31,186,37));deleteWordChinese.setFont(new" 宋體",Font.PLAIN,20));deleteWordChinese.setBounds(newRectangle(112,69,185,168));jScrollPane4.setBounds(newRectangle(297,31,139,206));deleteJList.setFont(new"宋體",Font.PLAIN,20));deleteJList.setForeground(Color.blue);255,deleteJList.setSelectionBackground(newColor(51,0));255,deleteOkButton.setBounds(newRectangle(437,31,83,);deleteOkButton.setFont(new"楷體",Font.PLAIN,20));deleteOkButton.setForeground(newColor(0,187,55));deleteOkButton.setText(" 刪除");scanButton.setForeground(newColor(0,214,0));scanButton.setText(" 瀏覽");jScrollPane5.setBounds(newRectangle(25,59,146,178));scanOutput.setColumns(5);scanOutput.setFont(new" 宋體",Font.PLAIN,20));scanOutput.setBounds(newRectangle(188,60,315,177));scanWordJList.setFont(new" 宋體",Font.PLAIN,20));scanWordJList.setForeground(Color.blue);scanWordJList.setSelectionBackground(Color.green);jLabel11.setFont(new" 楷體",Font.PLAIN,45));jLabel11.setForeground(newColor(0,255,138));jLabel11.setText("歡迎訪問詞庫");jLabel11.setBounds(newRectangle(197,8,287,40));deleteCancelButton.setBounds(newRectangle(437,96,83,34));deleteCancelButton.setFont(new" 楷體",Font.PLAIN,20));deleteCancelButton.setForeground(newColor(0,221,42));deleteCancelButton.setToolTipText("");deleteCancelButton.setText(" 取消");pronunciationJList.setSelectionBackground(newColor(51,255,125));sound.setBounds(newRectangle(420,24,74,33));sound.setFont(new"宋體",Font.PLAIN,20));sound.setToolTipText("");sound.setText("發(fā)音");inputSearchWord.setBounds(newRectangle(117,24,302,35));scanButton.setBackground(newColor(240,240,240));scanButton.setFont(new" 宋體",Font.PLAIN,20));scanSoundButton.setBounds(newRectangle(110,15,79,37));scanSoundButton.setFont(new" 宋體",Font.PLAIN,20));scanSoundButton.setText("發(fā)音");scanButton.setBounds(newRectangle(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" 楷體",Font.PLAIN,45));jLabel1.setForeground(Color.blue);jLabel1.setText("藍氏簡易英漢詞典");jLabel1.setBounds(newRectangle(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(newDimension(560,385));//第一個參//為長度,第二個參數(shù)為高度// 英漢互譯模塊函數(shù)調(diào)用 ////發(fā)音按鈕監(jiān)聽器sound.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){sound_actionPerformed(e);}});//查找輸入框監(jiān)聽器inputSearchWord.addCaretListener(newCaretListener(){publicvoidcaretUpdate(CaretEvente){inputSearch_caretUpdate(e);}});//查找單詞列表監(jiān)聽器listSearchEnglish.addMouseListener(newMouseAdapter(){publicvoidmouseClicked(MouseEvente){listSearchEnglish_mouseClicked(e);}});// 添加面板模塊函數(shù)調(diào) ////新單詞輸入框監(jiān)聽器inputNewWord.addCaretListener(newCaretListener(){publicvoidcaretUpdate(CaretEvente){inputNewWord_caretUpdate(e);}});//新單詞音標輸入框監(jiān)聽器pronunciation.addCaretListener(newCaretListener(){publicvoidcaretUpdate(CaretEvente){pronunciation_caretUpdate(e);}});//音標選擇列表鼠標監(jiān)聽器pronunciationJList.addMouseListener(newMouseAdapter(){publicvoidmouseClicked(MouseEvente){pronunciationJList_mouseClicked(e);}});//添加按鈕監(jiān)聽器addOkJButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){addOkJButton_actionPerformed(e);}});//取消添加單詞按鈕監(jiān)聽器addCancelButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){addCancelButton_actionPerformed(e);}});// 刪除模塊函數(shù)調(diào)用 ////刪除單詞輸入框監(jiān)聽器inputDeleteWord.addCaretListener(newCaretListener(){publicvoidcaretUpdate(CaretEvente){inputDeleteWord_caretUpdate(e);}});//刪除單詞列表框鼠標監(jiān)聽器deleteJList.addMouseListener(newMouseAdapter(){publicvoidmouseClicked(MouseEvente){deleteJList_mouseClicked(e);}});//刪除按鈕監(jiān)聽器deleteOkButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){deleteOkButton_actionPerformed(e);}});//取消刪除按鈕監(jiān)聽器deleteCancelButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){deleteCancelButton_actionPerformed(e);}
});// 瀏覽數(shù)據(jù)庫函數(shù)調(diào)用 ////瀏覽詞庫單詞發(fā)音按鈕監(jiān)聽器scanSoundButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){soundButton_actionPerformed(e);}});//瀏覽詞庫按鈕監(jiān)聽器scanButton.addActionListener(newActionListener(){publicvoidactionPerformed(ActionEvente){scanButton_actionPerformed(e);}});//瀏覽單詞列表鼠標監(jiān)聽器scanWordJList.addMouseListener(newMouseAdapter(){publicvoidmouseClicked(MouseEvente){scanWordJList_mouseClicked(e);});}String"h","s",I!I!I£,I!listItem[]});}String"h","s",I!I!I£,I!listItem[]g","i:","i","j","k","l","m",t","u","u:","ju:","v","w","z",","\u00F0","\u0259","\u0259u","\u0254:","\u0254",A","\u00E6"," a,"a","ai","ei","tr","dr","au","ts","dz","d3","t /","/",};DefaultListModelmodel=newDefaultListModel();JTabbedPanemainJP=newJTabbedPane();JLabeljLabel1=newJLabel();JPanelsearchEnglishOrChineseJP=newJPanel();JPaneladdWordJP=newJPanel();JPaneldeleteJP=newJPanel();JPanelscanStock=newJPanel();JLabeljLabel2=newJLabel();JTextFieldinputSearchWord=newJTextField();1!/!! Hill I!I!I!I!"I! H:H H:HII,I!II:b","c", "d","n",":","p",I!I!n,I!"e","f","r",億"3,JScrollPanejScrollPane1=newJScrollPane();JListlistSearchEnglish=newJList(model);TextAreaoutputSearchEnglish=newTextArea();JLabeljLabel4=newJLabel();JTextFieldinputNewWord=newJTextField();JLabeljLabel5=newJLabel();JLabeljLabel6=newJLabel();JTextFieldpronunciation=newJTextField();JComboBoxnewWordClass=newJComboBox();JScrollPanejScrollPane3=newJScrollPane();JListpronunciationJList=newJList(listItem);JLabeljLabel7=newJLabel();JTextFieldnewWordChinese=newJTextField();JLabeljLabel8=newJLabel();JTextFieldnewWordPreterite=newJTextField();JLabeljLabel9=newJLabel();JTextFieldnewWordModernism=newJTextField();JButtonaddOkJButton=newJButton();JButtonaddCancelButton=newJButton();JLabeljLabel10=newJLabel();JTextFieldinputDeleteWord=newJTextField();TextAreadeleteWordChinese=newTextArea();JScrollPanejScrollPane4=newJScrollPane();JListdeleteJList=newJList(model);JButtondeleteOkButton=newJButton();JButtonscanButton=newJButton();JScrollPanejScrollPane5=newJScrollPane();JListscanWordJList=newJList(model);TextAreascanOutput=newTextArea();JLabeljLabel11=newJLabel();StringnewWord,indexWord="",deleteWord,searchEnglish,searchChinese,isSound;Stringpronunciations;//發(fā)音變量JButtondeleteCancelButton=newJButton();Borderborder1=BorderFactory.createEmptyBorder();TitledBordertitledBorder1=newTitledBorder("");JButtonsound=newJButton();JButtonscanSoundButton=newJButton();/*方法簡介:由于特殊音標字符無法存入數(shù)據(jù)庫,只能以其他字符代替存入數(shù)據(jù)庫,從數(shù)據(jù)庫讀取輸出時再還原,這里用0、1、2、4分別代替字符?、?、‘、? 通過str.replace()替換還原*/publicstaticStringReturn(Stringstr){inti,length;length=str.length();for(i=1;i<=length;i++){str=str.replace("1","\u0259");str=str.replace("0","\u0254");str=str.replace("2","'");str=str.replace("4","\u00E6");length--;}returnstr;}/*方法簡介:根據(jù)要查找的單詞(去掉兩端空格),在音頻文件找匹
配的音頻,通過輸入流進行轉(zhuǎn)換,將其播放(限于 wav格式)*/publicvoidPlay(Stringword){SourceDataLinesdl=null;word=word.trim();Stringfileurl="Database/sound/"+word+".wav";try{AudioInputStreamais=AudioSystem.getAudioInputStream(newFile(fileurl));AudioFormataif=ais.getFormat();DataLine.Infoinfo=newDataLine.Info(SourceDataLine.class,aif);sdl=(SourceDataLine)AudioSystem.getLine(info);sdl.open(aif);sdl.start();//playintnByte=0;byte[]buffer=newbyte[128];while(nByte!=-1){nByte=ais.read(buffer,0,128);if(nByte>=0){intoByte=sdl.write(buffer,0,nByte);}}sdl.stop();}catch(UnsupportedAudioFileExceptione){e.printStackTrace();}catch(IOExceptione){e.printStackTrace();}catch(LineUnavailableExceptione){e.printStackTrace();}}// 英漢互譯模塊方法 ///*方法簡介:當inputSearch輸入框值改變時,listSearchEnglish列表框和outputSearchEnglish文本輸出框被清空,取inputSearch輸入框值賦給indexWord,如果indexWord不為空,連接數(shù)據(jù)庫;再判斷要查找的是英語,還是漢語,根據(jù)判斷結(jié)果進行查找,并將結(jié)果集按升序排列,輸出到listSearchEnglish列表框*/publicvoidinputSearch_caretUpdate(CaretEvente){((DefaultListModel)listSearchEnglish.getModel()).removeAllElements();outputSearchEnglish.setText("");indexWord=inputSearchWord.getText();indexWord=indexWord.trim();if(!indexWord.equals("")){char[]Is=indexWord.toCharArray();try{try{Class.forName("");}catch(ClassNotFoundExceptionex1){}connection=DriverManager.getConnection("jdbc:odbc:Driver={MicroSoftAccessDriver(*.mdb)};DBQ=Database\\englishWord.mdb","","");statement=connection.createStatement();}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"溫馨提示",1);}if(Is[0]>96&&Is[0]<123){searchEnglish=indexWord;Stringsql="select*fromwordstockwherewordLIKE'"+searchEnglish+"%'orderbywordASC";try{Result=statement.executeQuery(sql);while(Result.next()){model.addElement(Result.getString("word")+"\n");listSearchEnglish.setModel(model);}}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"溫馨提示",1);}}else{searchChinese=indexWord;Stringsql="select*fromwordstockwherechineseLIKE'%"+searchChinese+"%'orderbywordASC";try{Result=statement.executeQuery(sql);while(Result.next()){model.addElement(Result.getString("word")+"\n");listSearchEnglish.setModel(model);}connection.close();statement.close();}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"溫馨提示",1);}}}}/*方法簡介:當鼠標單擊listSearchEnglish列表框時,取所選選項的值賦給變量searchEnglish,去掉其兩端空格outputSearchEnglish文本輸出框被清空,發(fā)音按鈕變成灰,白色,從數(shù)據(jù)庫讀取要查找的單詞,將其音標進行還原,將單詞信息輸出到outputSearchEnglish文本框,如果可以音,發(fā)音按鈕變紅色,否則indexWord被賦給空值*/publicvoidlistSearchEnglish_mouseClicked(MouseEventme){if(me.getClickCount()==1){//單擊searchEnglish=(String)listSearchEnglish.getSelectedValue();searchEnglish=searchEnglish.trim();if(!searchEnglish.equals("")){try{try{Class.forName("");}catch(ClassNotFoundExceptionex1){}connection=DriverManager.getConnection("jdbc:odbc:Driver={MicroSoftAccessDriver(*.mdb)};DBQ=Database\\englishWord.mdb","","");statement=connection.createStatement();}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"連接數(shù)據(jù)庫失敗",1);}indexWord=searchEnglish;outputSearchEnglish.setText("");sound.setBackground(newColor(240,240,240));Stringsql="select*fromwordstockwhereword='"+searchEnglish+"'";try{Result=statement.executeQuery(sql);if(Result.next()){
StringWordclass=Result.getString("wordClass");StringChinese=Result.getString("chinese");StringPronunciation=Return(Result.getString("pronunciation"));StringPreterite=Result.getString("preterite");StringModernism=Result.getString("modernism");outputSearchEnglish.append(""+Result.getString("word")+"\n");if(!Pronunciation.equals(""))outputSearchEnglish.append("音:"+Pronunciation+"\n");if(!Wordclass.equals(""))outputSearchEnglish.append("性:"+Wordclass+"\n");outputSearchEnglish.append(""+Chinese+"\n");if(!Preterite.equals(""))outputSearchEnglish.append("去式:"+Preterite+"\n");if(!Modernism.equalsIgnoreCase(""))outputSearchEnglish.append("在式:"+Modernism+"\n");}isSound=Result.getString("sound");if(isSound.equals("Y")){sound.setBackground(new79));}else{indexWord="";}connection.close();statement.close();單詞:發(fā)詞單詞:發(fā)詞注釋:過現(xiàn)Color(255,0,scanOutput.append(ex2.getMessage());}}}}//方法簡介:如果查找單詞有音頻且查找詞不為空,則可發(fā)音,//否則按鈕變?yōu)榛野咨玴ublicvoidsound_actionPerformed(ActionEvente){if(isSound.equals("Y")&&!indexWord.equals("")){Play(indexWord);}else{sound.setBackground(newColor(240,240,240));}}// 添加模塊方法 ////方法簡介:當輸入的新單詞不是小寫字母或空格時,彈出提示框publicvoidinputNewWord_caretUpdate(CaretEvente){newWord=inputNewWord.getText();char[]Is=newWord.toCharArray();intlength=newWord.length();for(inti=0;i<length;i++){if(!((Is[i]>96&&Is[i]<123)||Is[i]==32)){JOptionPane.showMessageDialog(englishFrame.this,"只能輸入小寫字母和空格\n否則會出錯!","溫馨提示",1);inputNewWord.setText("");break;}}}/*方法簡介:對輸入的音標進行處理,因為字符?、?、‘、?存入數(shù)據(jù)庫時會變成?或出錯,所以用0、1、2、4分別代替他們讀取時通過調(diào)用Return函數(shù)還原,且將音標兩端和中間空格去掉*/publicvoidpronunciation_caretUpdate(CaretEvente){inti,length;pronunciations=pronunciation.getText();length=pronunciations.length();for(i=1;i<=length;i++){//去掉音標中的兩個或兩個以上的空格留一個空格且進行替換特殊字符pronunciations=pronunciations.replace("","");pronunciations=pronunciations.replace("\u0259","1");pronunciations=pronunciations.replace("\u0254","0");pronunciations=pronunciations.replace("'","2");pronunciations=pronunciations.replace("\u00E6","4");length--;}pronunciations=pronunciations.replace("","");pronunciations=pronunciations.trim();}/*方法簡介:當在音標選項列表單擊鼠標選擇音標時,將所選音標輸入音標輸入框*/publicvoidpronunciationJList_mouseClicked(MouseEventme){if(me.getClickCount()==1){//單擊Stringe=(String)pronunciationJList.getSelectedValue();pronunciations=pronunciation.getText()+e;pronunciation.setText(pronunciations);}}/*方法簡介:讀取未讀取的數(shù)據(jù),去掉單詞、注釋各自兩端空格,并將去掉它們各自中間兩個或兩個以上的空格留一個空格,接著在數(shù)據(jù)庫查找添加的單詞是否已存在,如已存在,彈出提示框,不能再添加,否則向數(shù)據(jù)庫添加新單詞信息,最后清空所有輸入框*/publicvoidaddOkJButton_actionPerformed(ActionEvente){intlength,i;Stringchinese=newWordChinese.getText();StringwordClass=(String)newWordClass.getSelectedItem();StringwordPeterite=newWordPreterite.getText();StringwordModernism=newWordModernism.getText();
Stringsearch;length=newWord.length();for(i=1;i<=length;i++){上的空格留一個空格newWord=newWord.replace(length--;}newWord=newWord.trim();//length=chinese.length();for(i=1;i<=length;i++){//兩個以上的空格留一個空格chinese=chinese.replace(length--;}chinese=chinese.trim();//Stringsearch;length=newWord.length();for(i=1;i<=length;i++){上的空格留一個空格newWord=newWord.replace(length--;}newWord=newWord.trim();//length=chinese.length();for(i=1;i<=length;i++){//兩個以上的空格留一個空格chinese=chinese.replace(length--;}chinese=chinese.trim();//JOptionPanemsg=newJOptionPane();try{try{Class.forName("");}catch(ClassNotFoundExceptionex1){}connection=I!I!I!I!I!//去掉單詞中的兩個或兩個以"");去掉單詞兩端空格去掉漢語釋義中的兩個或I!);去掉漢譯兩端空格DriverManager.getConnection("jdbc:odbc:Driver={MicroSoftAccessDriver(*.mdb)};DBQ=Database\\englishWord.mdb","","");statement=connection.createStatement();}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"連接數(shù)據(jù)庫失敗",1);}Stringsql="INSERTINTOwordstockvalues('"+newWord+"','"+pronunciations+"','"+wordClass+"','"+chinese+"','"+wordPeterite+"','"+wordModernism+"','N')";search="select*fromwordstockwhereword='"+newWord+"'";if(newWord.equals("")){JOptionPane.showMessageDialog(englishFrame.this,"請輸入單詞!","溫馨提示",1);}else{try{Result=statement.executeQuery(search);if(Result.next()){JOptionPane.showMessageDialog(englishFrame.this,"詞庫已存在該單詞\n不能再添加"+Result.getString("word"),"溫馨提示"1);connection.close();statement.close();}else{statement.executeUpdate(sql);JOptionPane.showMessageDialog(englishFrame.this,"單詞加入成功","添加單詞",1);connection.close();statement.close();}}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"單詞添加數(shù)據(jù)庫失敗",1);}pronunciation.setText("");inputNewWord.setText("");newWordChinese.setText("");newWordPreterite.setText("");newWordModernism.setText("");}}//方法簡介:點擊取消按鈕,所有輸入框被清空publicvoidaddCancelButton_actionPerformed(ActionEvente){newWord=null;inputNewWord.setText(newWord);newWordChinese.setText("");pronunciation.setText("");newWordPreterite.setText("");newWordModernism.setText("");}// 刪除模塊方法 ///*方法簡介:當inputDeleteWord輸入框值改變時,清空deleteJList列表框,讀取inputDeleteWord輸入框值賦給變量deleteWord,按模糊查找法查找以deleteWord的值開頭的所有單詞,按升序排列,并將他們輸出到deleteJList列表框*/publicvoidinputDeleteWord_caretUpdate(CaretEvente){((DefaultListModel)deleteJList.getModel()).removeAllElements();deleteWord=inputDeleteWord.getText();try{try{Class.forName("");}catch(ClassNotFoundExceptionex1){}connection=DriverManager.getConnection("jdbc:odbc:Driver={MicroSoftAccessDriver(*.mdb)};DBQ=Database\\englishWord.mdb","","");statement=connection.createStatement();}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"連接數(shù)據(jù)庫失敗",1);}Stringsql="select*fromwordstockwherewordLIKE'"+deleteWord+"%'orderbywordASC";try{Result=statement.executeQuery(sql);while(Result.next()){model.addElement(Result.getString("word")+"\n");deleteJList.setModel(model);}connection.close();statement.close();}catch(SQLExceptionex){JOptionPane.showMessageDialog(englishFrame.this,ex.getMessage(),"連接數(shù)據(jù)庫失敗",1);}}/*方法簡介:當在deleteJList列表框單擊選項時,讀取選項值賦給deleteWord變量,并去掉其兩端空格,向inputDeleteWord輸入框輸入deleteWord變量值,接著從數(shù)據(jù)庫讀取要刪除的單詞的信息,如某屬性不為空,將其輸入到eleteWordChinese多行文本框*/publicvoiddeleteJList_mouseClicked(MouseEventme){if(me.getClickCount()==1){deleteWord=(String)deleteJList.getSelectedValue();deleteWord=deleteWord.trim();inputDeleteWord.setText(deleteWord);try{t
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 《皮膚性病學濕疹》課件
- 行政后勤財務(wù)報銷審核
- 母親節(jié) 營銷新視角
- 體育行業(yè)話務(wù)員工作總結(jié)
- 2023-2024年企業(yè)主要負責人安全培訓考試題考題
- 2023-2024安全培訓考試題及答案(新)
- 函授專科畢業(yè)自我鑒定15篇
- 課題研究報告
- 通宣理肺丸的現(xiàn)代化改造-洞察分析
- 血型抗原抗體相互作用機制-洞察分析
- 2024年全國鄉(xiāng)村醫(yī)生考試復(fù)習題庫及答案(共360題)
- 全屋定制家具店合伙經(jīng)營協(xié)議書2024年
- 建筑施工安全生產(chǎn)隱患識別圖集(鋼結(jié)構(gòu)工程)
- 城市道路與開放空間低影響開發(fā)雨水設(shè)施
- 電氣二次危險點分析及控制措施
- 初中必背古詩文138首
- 藍色國家科學基金4.3杰青優(yōu)青人才科學基金答辯模板
- DLT 5434-2021 電力建設(shè)工程監(jiān)理規(guī)范表格
- 2024年房屋交接確認書
- 拓展低空經(jīng)濟應(yīng)用場景實施方案
- 北京市東城區(qū)2023-2024學年八年級上學期期末生物試題【含答案解析】
評論
0/150
提交評論