



下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、實(shí)驗(yàn)一簡(jiǎn)單的單詞識(shí)別程序一、實(shí)驗(yàn)內(nèi)容設(shè)計(jì)一個(gè)識(shí)別單詞的程序,從文本文件中讀取字符串,將字符串中的字符根據(jù)空格逐個(gè) 識(shí)別為單詞,并比較單詞是否為 zero,one,two, three,four,five,six,seven,eight,nine, 若是則輸出該單詞對(duì)應(yīng)的阿拉伯?dāng)?shù)字。要求用java語(yǔ)言、閣形界而方式編程。(可參考實(shí) 驗(yàn)指導(dǎo)書p110至p113)舉例:若文本文件中的字符串為one at are three six 234 eight則輸山為1368二、程序代碼distinguishword.javapackage zlf;import java.io.*;import java.a
2、wt.*;import java.awt.event.*;import javax.swing.*;public class distinguishword extends jappletprivate jfilechooser jfc = new jfilechooser (new file ( n .;private jtextarea jtal = new jtextarea();private jtextarea jta2 = new jtextarea();private jbutton jlbl = new jbutton ("字符串的人j容為:");priva
3、te jbutton jlb2 = new jbutton ("其中英文對(duì)應(yīng)的阿拉伯?dāng)?shù)字為:")private jlabel filename = new jlabel(n filename ");private jtextfield jtf = new jtextfield (30);private jbutton brower = new jbutton("brower”);public distinguishword()jpanel pi = new jpanel();pi-setlayout(new borderlayout();pisetbor
4、der(borderfactorycreateemptyborder(5, 5,5,10); pi.add(jlbl,borderlayout.north);pi.add(new jscrollpane(jtal), borderlayout.center); add(pi,borderlayout.center);jpanel p2 = new jpanel();p2.setlayout(new borderlayout();p2.setborder(borderfactory.createemptyborder(5,5,5,10); p2add(jlb2,borderlayout.nort
5、h);p2.add(new jscrollpane(jta2), borderlayout.center); add(p2,borderlayout-east);jpanel p3 = new jpanel();p3.setlayout(new borderlayout(); p3.add (filename,borderlayout.west); p3.add(jtf);p3.add(brower, borderlayout.east); add(p3,borderlayout.south); jtf.settext("c:/i.txt");brower.addactio
6、nlistener(new actionlistener() public void actionperformed(actionevent e)open(););jtf.addkeylistener(new keyadapter()public void keypressed(keyevent e)if (e . getkeychar () =keyevent. vk_enter )/按回午鍵執(zhí)行相!、;/:操作;string file = jtf.gettext ();try bufferedinputstream in = new bufferedlnputstream(new file
7、lnputstream(file);byte b = new bytein.available(); in.read(b,0,blength);jtal.append(new string(b,0,b.length); in.close(); catch (ioexception el) jtal.settext("error opening "););jlb2.addactionlistener(new actionlistener() public void actionperformed(actionevent e)string s = jtal.gettext();
8、jta2settext(translatefigure(s););private string translatefigure (string string) string english ="zero","one","two","three","four","five","six","seven","eight", "ninestring s = string;string str = n"st
9、ring t = 11 ,f ; int n = 0;char ch = s.tochararray();for (int i = 0; i < s. length。; i + +) if(chi = '* |lchi = '.* |lchi = *, ')t = s.substring(n, i); n = i+1;for(int j = 0; j < 10; j+) if(tequals(english j)str = str + j;return str;private void open () if(jfc.showopendialog(this)
10、= jfilechooser.approve_option) open(jfc.getselectedfile();private void open (file file) trybufferedlnputstream in = new bufferedlnputstream(new filelnputstream(file);byte b = new bytein.available (); in.read(b,0,b.length);jtal.append(new string(b,0,blength); in.close ();jtf.settext(file.getname();catch(ioexception ex)jtf set text (11 error opening " + file . getname ();1. txtone at are three six 234 eight三、實(shí)驗(yàn)結(jié)果 截圖:小應(yīng)用程序browerfilename已啟動(dòng)小應(yīng)用程序,簡(jiǎn)單說(shuō)明:字符串內(nèi)容框內(nèi)可輸入內(nèi)界,點(diǎn)擊“其中英文對(duì)應(yīng)的阿拉伯?dāng)?shù)字為:”按鈕可得 出結(jié)果,或者在filename后輸入文件路徑與文件名后回車,字符串內(nèi)容框會(huì)顯示文本文件 內(nèi)容
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 跨平臺(tái)整合提高品牌營(yíng)銷效率的關(guān)鍵
- 防火設(shè)備的使用及維護(hù)超市消防器材培訓(xùn)重點(diǎn)
- 浙江國(guó)企招聘2024嘉興海寧上塘水務(wù)有限公司高品質(zhì)管道飲用水工作辦公室招聘4人筆試參考題庫(kù)附帶答案詳解
- 食品藥品行業(yè)行政法規(guī)的嚴(yán)格性與透明度
- 高中物理1.2時(shí)間位移練習(xí)2含解析人教版必修第一冊(cè)
- 財(cái)務(wù)軟件報(bào)表制作與數(shù)據(jù)分析技巧
- 金融科技背景下的財(cái)務(wù)團(tuán)隊(duì)能力提升
- 高效辦公降低血透室并發(fā)癥風(fēng)險(xiǎn)
- 跨區(qū)域醫(yī)療中心信息化建設(shè)的經(jīng)驗(yàn)分享
- 河南2025年01月2025年河南濮陽(yáng)市市直機(jī)關(guān)遴選公務(wù)員29人國(guó)家公務(wù)員考試消息筆試歷年典型考題(歷年真題考點(diǎn))解題思路附帶答案詳解
- 四川省既有居住小區(qū)改造技術(shù)標(biāo)準(zhǔn)
- 慢性血栓栓塞性肺動(dòng)脈高壓診斷與治療指南(2024版)解讀
- 2024年南京科技職業(yè)學(xué)院?jiǎn)握新殬I(yè)適應(yīng)性測(cè)試題庫(kù)完整
- 小學(xué)生國(guó)家文化安全教育
- 2024年常州工業(yè)職業(yè)技術(shù)學(xué)院?jiǎn)握新殬I(yè)技能測(cè)試題庫(kù)及答案解析
- AQ-T 3002-2021阻隔防爆橇裝式加油(氣)裝置技術(shù)要求
- 綠植租擺投標(biāo)方案
- 新聞編輯學(xué)PDF蔡雯第四版
- 行政處罰自由裁量權(quán)課件
- Unit-3-Reading-and-thinking課文詳解課件-高中英語(yǔ)人教版必修第二冊(cè)
- 肝病科進(jìn)修總結(jié)匯報(bào)
評(píng)論
0/150
提交評(píng)論