Java txt小說(shuō)閱讀器實(shí)驗(yàn)報(bào)告_第1頁(yè)
Java txt小說(shuō)閱讀器實(shí)驗(yàn)報(bào)告_第2頁(yè)
Java txt小說(shuō)閱讀器實(shí)驗(yàn)報(bào)告_第3頁(yè)
Java txt小說(shuō)閱讀器實(shí)驗(yàn)報(bào)告_第4頁(yè)
Java txt小說(shuō)閱讀器實(shí)驗(yàn)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、1.功能分析功能邏輯圖:根據(jù)功能邏輯分析圖,txt小說(shuō)閱讀器應(yīng)該具備以下功能:文件的打開(kāi)及關(guān)閉字體的設(shè)置查找功能底部按鈕(首頁(yè)、尾頁(yè)、上一頁(yè),下一頁(yè),滾屏)雙擊窗體自動(dòng)滾屏,單擊窗體停止?jié)L屏2.功能實(shí)現(xiàn)、設(shè)計(jì),分析2.1文件的打開(kāi)2.11功能實(shí)現(xiàn)2.1.2功能設(shè)計(jì)實(shí)現(xiàn)的關(guān)鍵代碼:監(jiān)視器:open.addActionListener(newActionListener()/打開(kāi)publicvoidactionPerformed(ActionEvente)fileOpen(););2privatevoidfileOpen()/文件對(duì)話框intflag=fileDialog.showOpenDial

2、og(this);if(flag=JFileChooser.APPROVE_OPTION)/獲得該文件Filf=fileDialog.getSelectedFile();textArea.setText(null);tryFiledir=fileDialog.getCurrentDirectory();/返回當(dāng)前目錄Stringname=fileDialog.getSelectedFile().getName();Filefile=newFile(dir,name);fileReader=newFileReader(file);in=newBufferedReader(fileReader);

3、Strings=null;while(s=in.readLine()!=null)textArea.append(s+n);in.close();fileReader.close();textArea.setCaretPosition(0);/讓一開(kāi)始滾動(dòng)條就在取上方catch(IOExceptionexp)213功能分析經(jīng)過(guò)實(shí)驗(yàn)及測(cè)試,實(shí)現(xiàn)的文件對(duì)話框可以正常打開(kāi)任何文件txt文件,但打開(kāi)doc文件時(shí)會(huì)出現(xiàn)亂碼的情況22字體的設(shè)置2.2.1功能實(shí)現(xiàn)2.2.2功能設(shè)計(jì)實(shí)現(xiàn)的關(guān)鍵代碼:監(jiān)視器:font.addActionListener(newActionListener()/字體設(shè)置publi

4、cvoidactionPerformed(ActionEvente)font1.addEventHandler(););2classfont/字體設(shè)置privateJTextAreatextArea;privateJButtonok,cancel;privateJComboBoxfontName,fontSize,fontStyle;GraphicsEnvironmentge;/定義系統(tǒng)字體對(duì)象Stringsize=8,10,12,14,16,18,20,22,24,26,28,32,36,48,72,96;Stringstyle=PLAIN,BOLD,ITALIC;JFramejf=newJ

5、Frame(”字體設(shè)置”);publicfont(JTextAreatextArea)this.textArea=textArea;TOC o 1-5 h zJLabellabel1=newJLabel(字體);JLabellabel2=newJLabel(字號(hào));JLabellabel3=newJLabel(樣式);ge=GraphicsEnvironment.getLocalGraphicsEnvironment();/獲取系統(tǒng)字體Stringfontname=ge.getAvailableFontFamilyNames();fontName=newJComboBox(fontname);

6、fontSize=newJComboBox(size);fontStyle=newJComboBox(style);ok=newJButton(確定);cancel=newJButton(取消);jf.setLayout(newBorderLayout();JPanelp1=newJPanel();/P236JPanelp2=newJPanel();JPanelp3=newJPanel();p1.add(label1);p1.add(label2);p1.add(label3);p2.add(fontName);p2.add(fontSize);p2.add(fontStyle);p3.add

7、(ok);p3.add(cancel);jf.add(p1,BorderLayout.NORTH);/布局,放置的位置jf.add(p2,BorderLayout.CENTER);jf.add(p3,BorderLayout.SOUTH);jf.setSize(360,200);jf.setLocation(300,200);jf.setvisiblefalse);jf.setResizablefalse);/大小不可調(diào)整publicvoidaddEventHandler()/TODOAuto-generatedmethodstubjf.setVisible(true);/由原先的不可見(jiàn)-可見(jiàn)

8、ok.addActionListener(newActionListener()publicvoidactionPerformed(ActionEvente)Stringn1=(String)fontName.getSelectedItem();intn2=fontStyle.getSelectedIndex();Stringn3=(String)fontSize.getSelectedItem();textArea.setFont(newFont(n1,n2,Integer.parselnt(n3);jf.setVisiblefalse);/點(diǎn)擊“確定”按鈕后-不可見(jiàn));cancel.add

9、ActionListener(newActionListener()publicvoidactionPerformed(ActionEvente)jf.setVisiblefalse);/若是點(diǎn)擊了“取消”按鈕-僅僅讓對(duì)話框消失即可);223功能分析實(shí)現(xiàn)設(shè)置字體的該窗體可以實(shí)現(xiàn)設(shè)置字體的類(lèi)型、大小、顏色、是否加粗、傾斜等設(shè)置,但當(dāng)設(shè)置為一些字體類(lèi)型時(shí),文本會(huì)出現(xiàn)亂碼的情況,原因可能是字體編碼不一樣導(dǎo)致的23查找功能231功能實(shí)現(xiàn)2.3.2功能設(shè)計(jì)實(shí)現(xiàn)的關(guān)鍵代碼:監(jiān)視器:find.addActionListener(newActionListener()publicvoidactionPerfo

10、rmed(ActionEvente)findtest=newFind(textArea,x,y);findtest.findset(););2importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;publicclassFindimplementsActionListener,DocumentListenerprivateJFramejframe;privateJLabeljlabel;privateJTextFieldjtextFile;privateJButtonjbtNex

11、t;privateJButtonjbtCancel;JTextAreatextArea;inti=0;intx,y;publicFind(JTextAreatextArea,intx,inty)this.x=x;this.y=y;this.textArea=textArea;jframe=newJFrame();jlabel=newJLabel(查找內(nèi)容:”);jtextFile=newJTextField(10);jbtNext=newJButton(”查找下一個(gè)”);jbtCancel=newJButton(”取消”);jframe.setLayout(newFlowLayout();jf

12、rame.add(jlabel);jframe.add(jtextFile);jframe.add(jbtNext);jframe.add(jbtCancel);jframe.setBounds(x+200,y+200,220,120);jframe.setvisible(false);/jtextFile.setEditable(true);jframe.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);/jframe.pack();voidfindset()jframe.setvisible(true);jbtNext.addActionList

13、ener(this);jbtCancel.addActionListener(newActionListener()publicvoidactionPerformed(ActionEventarg0)jframe.setvisible(false);/一旦點(diǎn)擊“取消”按鈕后對(duì)話框馬上消失jtextFile.setText(null);/點(diǎn)擊“取消”按鈕之后,文本框清空i=0;/點(diǎn)擊“取消”按鈕之后,i重新賦值0,即下一次查找從頭開(kāi)始);(jtextFile.getDocument().addDocumentListener(this);/監(jiān)視文本框P251Overridepublicvoida

14、ctionPerformed(ActionEvente)Stringstring=jtextFile.getText().trim();/獲取文本框中的內(nèi)容if(!(.equals(string)/空字符串與用戶(hù)輸入的字符串作比較P189Stringstr=textArea.getText();/獲取textArea的內(nèi)容if(i!=-1)/防止當(dāng)i=-1時(shí),下面這行代碼會(huì)把i=-1重新賦值,導(dǎo)致從頭再查找-查找到尾部后不允許從頭重新查找i=str.indexOf(string,i);/192if(i=0)textArea.setSelectionStart(i);textArea.setSe

15、lectionEnd(i+string.length();elseJOptionPane.showMessageDialog(null,沒(méi)有找到+string);/消息對(duì)話框P285,放置在屏幕中間elseJOptionPane.showMessageDialog(null,輸入不能為空);if(i!=(-1)/為了能繼續(xù)查找下一個(gè)關(guān)鍵字i+=1;/System.out.println(i);/監(jiān)聽(tīng)文本框文本框一旦改變(增加、刪除、改變),i=0OverridepublicvoidchangedUpdate(DocumentEventarg0)/沒(méi)有下面兩個(gè)函數(shù),查找一次到頭了就不能再繼續(xù)查找

16、下一次了(即使修改查找內(nèi)容)/TODOAuto-generatedmethodstubi=0;OverridepublicvoidinsertUpdate(DocumentEventarg0)/在查找內(nèi)容的基礎(chǔ)上刪除/TODOAuto-generatedmethodstubchangedUpdate(arg0);OverridepublicvoidremoveUpdate(DocumentEventarg0)/在查找內(nèi)容的基礎(chǔ)上刪除/TODOAuto-generatedmethodstubchangedUpdate(arg0);2.3.3功能分析經(jīng)過(guò)試驗(yàn),測(cè)試,改進(jìn),以及再測(cè)試,該查找功能能完

17、善地實(shí)現(xiàn)查找的功能,精確定位到關(guān)鍵字,符合查找的規(guī)則2.4自動(dòng)滾屏2.4.1功能實(shí)現(xiàn)2.4.2功能設(shè)計(jì)實(shí)現(xiàn)的關(guān)鍵代碼:Timertimer=newTimer(delay,newActionListener()publicvoidactionPerformed(ActionEventevt)jsb.setvalue(jsb.getvalue()+jsb.getUnitIncrement();/設(shè)置滾動(dòng)條的值);textArea.addMouseListener(newMouseListener()/監(jiān)聽(tīng)鼠標(biāo)的點(diǎn)擊數(shù),執(zhí)行相應(yīng)的操作P252publicvoidmouseClicked(MouseE

18、vente)if(e.getClickCount()=2)/滾屏/timer.start();count=1;/為的是與底部的“滾屏按鈕對(duì)應(yīng)”timer.start();/為的是與底部的“滾屏按鈕對(duì)應(yīng)”roll.setText(”暫停滾屏”);if(e.getClickCount()=1)/停止?jié)L屏/timer.stop();count=0;timer.stop();roll.setText(自動(dòng)滾屏”);publicvoidmouseEntered(MouseEvente)publicvoidmouseExited(MouseEvente)publicvoidmousePressed(Mou

19、seEvente)publicvoidmouseReleased(MouseEvente);或者:roll.addActionListener(newActionListener()publicvoidactionPerformed(ActionEvente)if(+count)%2=1)/滾屏timer.start();roll.setText(”暫停滾屏”);else/停止?jié)L屏timer.stop();roll.setText(自動(dòng)滾屏”););2.4.3功能分析經(jīng)過(guò)試驗(yàn),測(cè)試,改進(jìn),以及再測(cè)試,點(diǎn)擊窗體下方的“自動(dòng)暫停滾屏”按鈕可以實(shí)現(xiàn)滾屏或是暫停滾屏。鼠標(biāo)雙擊/單擊窗體,可以實(shí)現(xiàn)實(shí)現(xiàn)滾

20、屏或是暫停滾屏,并且與窗體下方的“自動(dòng)/暫停滾屏”按鈕的文字相互協(xié)調(diào)、互相一致,保持同步25設(shè)計(jì)滾屏速度251功能實(shí)現(xiàn)2.5.2功能設(shè)計(jì)實(shí)現(xiàn)的關(guān)鍵代碼:監(jiān)視器:speed.addActionListener(newActionListener()/滾屏速度的設(shè)置publicvoidactionPerformed(ActionEvente)sped.liser(););2importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;classSpeedimplementsItemListenerprivateJScrollBarjsb;p

21、rivateJFramejfrm;privateJLabeljlbl;privateJButtonjbt;privateJComboBoxjcbb;Integersudu;速度Timertimer;計(jì)時(shí)器privateIntegermsg=1,2,3,4,5,6,7,8;publicSpeed(finalJScrollBarjsb,finalTimertimer)this.jsb=jsb;this.timer=timer;jfrm=newJFrame();jlb1=newJLabel(滾屏速度”);jbt=newJButton(確定);jcbb=newJComboBox(msg);jfrm.s

22、etLayout(newFlowLayout();jfrm.add(jlbl);jfrm.add(jcbb);jfrm.add(jbt);jfrm.setVisible(false);jcbb.setEditable(true);jfrm.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);jfrm.pack();voidliser()jfrm.setVisible(true);jcbb.addltemListener(this);/*關(guān)鍵jbt.addActionListener(newActionListener()“確定按鈕的監(jiān)聽(tīng)publicvo

23、idactionPerformed(ActionEventargO)jfrm.setVisible(false);一旦點(diǎn)擊“確定按鈕后對(duì)話框馬上消失);OverridepublicvoiditemStateChanged(ItemEventarg0)sudu=(Integer)jcbb.getSelectedItem();jsb.setUnitIncrement(Value();2.5.3功能分析經(jīng)過(guò)試驗(yàn)及測(cè)試,該功能可以實(shí)現(xiàn)對(duì)滾屏速度的設(shè)置,而且設(shè)置合理2.6分頁(yè)2.6.1功能實(shí)現(xiàn)2.6.2功能設(shè)計(jì)1上一頁(yè):PageUp.addActionListener(newAction

24、Listener()/上一頁(yè)publicvoidactionPerformed(ActionEvente)jspValue=scroll.getVerticalScrollBar().getvalue();scroll.getVerticalScrollBar().setValue(jspValue-=scroll.getHeight();2下一頁(yè):PageDown.addActionListener(newActionListener()/下一頁(yè)publicvoidactionPerformed(ActionEvente)jspValue=scroll.getVerticalScrollBar().getvalue();scroll.getVerticalScrollBar().setvalue(jspValue+

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論