java課程設(shè)計(jì)報(bào)告_第1頁(yè)
java課程設(shè)計(jì)報(bào)告_第2頁(yè)
java課程設(shè)計(jì)報(bào)告_第3頁(yè)
java課程設(shè)計(jì)報(bào)告_第4頁(yè)
java課程設(shè)計(jì)報(bào)告_第5頁(yè)
已閱讀5頁(yè),還剩9頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、Java課程設(shè)計(jì)報(bào)告 題 目: 文本編輯器 班 級(jí): 學(xué) 號(hào): 姓 名: 成 績(jī): 日期: 年 月 日目 錄一、綜合設(shè)計(jì)的目的與要求 3二、綜合設(shè)計(jì)正文31.系統(tǒng)分析31.1系統(tǒng)開(kāi)發(fā)背景、開(kāi)發(fā)范圍、建設(shè)目標(biāo)與必要性開(kāi)發(fā)31.2需求分析32.系統(tǒng)設(shè)計(jì)32.1功能設(shè)計(jì)32.2系統(tǒng)運(yùn)行環(huán)境與開(kāi)發(fā)工具43 .系統(tǒng)實(shí)施43.1源程序43.2. 系統(tǒng)測(cè)試及部分截圖12三、綜合設(shè)計(jì)總結(jié)或結(jié)論13四、參考文獻(xiàn)13文本編輯器一、綜合設(shè)計(jì)的目的與要求要求在學(xué)生能夠較熟練使用java程序設(shè)計(jì)語(yǔ)言進(jìn)行軟件代碼的編寫(xiě),同時(shí)還要具備較好的項(xiàng)目分析的能力,加深對(duì)相關(guān)課程基本內(nèi)容的理解。同時(shí),在程序設(shè)計(jì)方法以及上機(jī)操作等基本

2、技能和科學(xué)作風(fēng)方面受到比較系統(tǒng)的練習(xí)。二、綜合設(shè)計(jì)正文1 系統(tǒng)分析1.1系統(tǒng)開(kāi)發(fā)背景、開(kāi)發(fā)范圍、建設(shè)目標(biāo)與必要性隨著計(jì)算機(jī)科學(xué)日漸成熟,其強(qiáng)大的功能已為人們深刻認(rèn)識(shí),它已進(jìn)入人類(lèi)社會(huì)的各個(gè)領(lǐng)域并發(fā)揮著越來(lái)越重要的作用。當(dāng)然對(duì)文本編輯操作仍然占據(jù)著重要地位,記事本是簡(jiǎn)單便捷的文本編輯器,可實(shí)現(xiàn)對(duì)文本編輯操作的基本功能。1.2需求分析程序設(shè)計(jì)主要分為兩大部分:簡(jiǎn)單GUI設(shè)計(jì)和程序功能設(shè)計(jì)。通過(guò)GUI設(shè)計(jì)實(shí)現(xiàn)圖形用戶界面,提供圖形菜單,方便用戶操作。使用Java語(yǔ)言編寫(xiě)一個(gè)能夠?qū)斎胛淖诌M(jìn)行操作,具有合理的界面,能夠在界面中實(shí)現(xiàn)右鍵快捷方式,對(duì)文檔內(nèi)容進(jìn)行編輯操作,并且能夠順利退出的程序。通過(guò)設(shè)計(jì)和

3、實(shí)現(xiàn)一個(gè)具有基本功能的文本編輯器,提高我們對(duì)Java語(yǔ)言設(shè)計(jì)的掌握能力,理論聯(lián)系實(shí)際,進(jìn)一步提高軟件開(kāi)發(fā)技術(shù),從而培養(yǎng)我們分析、解決問(wèn)題的能力。2 系統(tǒng)設(shè)計(jì)2.1功能設(shè)計(jì)根據(jù)系統(tǒng)自帶的文檔編輯器的特征設(shè)計(jì),包括如下的功能模塊:一、 整體結(jié)構(gòu)框架包括:菜單欄和文檔編輯區(qū)二、 每個(gè)框架分別包含不同的子框架,各個(gè)模塊的具體框架:1.菜單欄:文件、編輯、工具、幫助2.菜單欄中各個(gè)子菜單功能文件:新建、打開(kāi)、保存、另存為、退出編輯:剪切、復(fù)制、粘貼 工具: 查找、替換 3.子菜單功能的實(shí)現(xiàn)主要的幾個(gè)功能介紹1) 打開(kāi)與另存為:兩個(gè)窗體調(diào)用系統(tǒng)函數(shù)直接利用,注意格式的選擇2) 查找:查找內(nèi)容、查找、查找下

4、一個(gè)4文本編輯區(qū)監(jiān)視文本內(nèi)容是否改變、監(jiān)聽(tīng)光標(biāo)所在位置 2.2系統(tǒng)運(yùn)行環(huán)境與開(kāi)發(fā)工具開(kāi)發(fā)環(huán)境與工具:jdk2.0 Eclipse SDK3 系統(tǒng)實(shí)施3.1源程序import javax.swing.*;import java.awt.*;import java.io.*;import java.awt.event.*;public class TxtEditor extends JFrame implements ActionListenerString file_name;String file_dir;String tempString;/上次保存后的文件名和地址String fileNa

5、me = ; JPanel x=new JPanel(); JTextArea wen=new JTextArea(20,50); JMenuItem ziti=new JMenuItem(字體); JMenuItem a=new JMenuItem(普通); /定義菜單項(xiàng) JMenuItem xin=new JMenuItem(新建); JMenuItem open=new JMenuItem(打開(kāi)); JMenuItem save=new JMenuItem(保存 ); JMenuItem lsave=new JMenuItem(另存為); JMenuItem tui=new JMenuI

6、tem(退出); JMenuItem cut=new JMenuItem(剪切 ); JMenuItem copy=new JMenuItem(復(fù)制); JMenuItem cast=new JMenuItem(粘貼); JMenuItem delete=new JMenuItem(刪除 ); JMenuItem b=new JMenuItem(粗體); JMenuItem c=new JMenuItem(斜體);TxtEditor() super (文本編輯器);/對(duì)話框 setBounds(250,100,700,450); setDefaultCloseOperation(DO_NOTH

7、ING_ON_CLOSE); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) int option= JOptionPane.showConfirmDialog( TxtEditor.this, 確定要退出嗎. , 系統(tǒng)和你對(duì)話 ,JOptionPane.YES_NO_OPTION); if(option=JOptionPane.YES_OPTION) if(e.getWindow() = TxtEditor.this) System.exit(0); else return; );

8、/熱鍵設(shè)置 xin.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK); open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,ActionEvent.CTRL_MASK); save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK); cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.V

9、K_X,ActionEvent.CTRL_MASK); copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK); cast.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK); /定義面板 / x.add( add(new JScrollPane (wen);/);/滾動(dòng)條 wen.setFont(new Font(楷體 , Font.PLAIN ,20); / wen.setBackgroun

10、d(Color.blue); / add(x); /菜單欄的創(chuàng)建 JMenuBar cai=new JMenuBar(); this.setJMenuBar(cai); cai.setOpaque(true); JMenu jian=new JMenu(文件); jian.add(xin); jian.add(open); jian.add(save); jian.add(lsave); jian.addSeparator( ); jian.add(tui); cai.add(jian); JMenu bian= new JMenu(編輯 ); bian.add(cut); bian.add(

11、copy); bian.add(cast); bian.add(delete); cai.add(bian); JMenu geshi = new JMenu (格式); JMenu optionsMenu=new JMenu(字體); geshi.add(optionsMenu); optionsMenu.add(a); optionsMenu.add(b); optionsMenu.add(c); cai.add(geshi); /增加監(jiān)聽(tīng)器 xin.addActionListener(this); open.addActionListener(this); save.addActionL

12、istener(this); lsave.addActionListener(this); tui.addActionListener(this); cut.addActionListener(this); copy.addActionListener(this); cast.addActionListener(this); delete.addActionListener(this); ziti.addActionListener(this); a.addActionListener(this); b.addActionListener(this); c.addActionListener(

13、this);/ 文本框鎖定 /this.setResizable(false); /重寫(xiě)方法public void actionPerformed(ActionEvent e)String actionCommand=e.getActionCommand();if(e.getSource()instanceof JMenu); if(e.getSource()=xin)newfile(); else if(e.getSource()=open) openfile(); else if(e.getSource()=save) savefile(); else if(e.getSource()=l

14、save) lsavefile(); else if(e.getSource()=cut) cutfile(); else if(e.getSource()=copy) copyfile(); else if(e.getSource()=cast) castfile(); else if(e.getSource()=delete) deletefile(); else if(e.getSource()=a) afile(); else if(e.getSource()=b) bfile(); else if(e.getSource()=c) cfile(); else if(退出.equals

15、(actionCommand) System.exit(0); / 方法定義 public void newfile() savefile(); wen.setText(null); fileName = ; /打開(kāi) public void openfile() String fileName = null; FileDialog df = new FileDialog(this,打開(kāi)文件,FileDialog.LOAD); df.setVisible(true); /建立新文件 File f = new File( df.getDirectory()+df.getFile() ); /得到文

16、件名 fileName = df.getDirectory()+df.getFile(); /用此文件的長(zhǎng)度建立一個(gè)字符數(shù)組 (特別標(biāo)注) char ch = new char (int)f.length(); /異常處理 try /讀出數(shù)據(jù),并存入字符數(shù)組ch中 BufferedReader bw = new BufferedReader( new FileReader(f) ); bw.read(ch); bw.close(); catch( FileNotFoundException fe ) System.out.println(file not found); System.exit

17、(0); catch( IOException ie) System.out.println(IO error); System.exit(0); String s =new String (ch); wen.setText(s); /保存 public void savefile() if( fileName.equals() ) FileDialog df = new FileDialog(this,保存文件,FileDialog.SAVE); df.addWindowListener( new WindowAdapter() public void windowClosing(Windo

18、wEvent ee) System.exit(0); ); df.setVisible(true); String s = wen.getText(); try File f = new File( df.getDirectory()+df.getFile(); fileName = df.getDirectory()+df.getFile(); BufferedWriter bw = new BufferedWriter( new FileWriter (f); bw.write(s , 0 , s.length(); bw.close(); catch(FileNotFoundExcept

19、ion fe_) System.out.println(file not found); System.exit(0); catch( IOException ie_) System.out.println( IO error); System.exit(0); /如果文件已經(jīng)保存過(guò) else String s = wen.getText(); try File f = new File( fileName ); BufferedWriter bw = new BufferedWriter( new FileWriter (f); bw.write(s , 0 , s.length(); bw

20、.close(); catch(FileNotFoundException fe_) System.out.println(file not found); System.exit(0); catch( IOException ie_) System.out.println( IO error); System.exit(0); /另存為 public void lsavefile() FileDialog df = new FileDialog(this,另存為,FileDialog.SAVE); df.addWindowListener( new WindowAdapter() publi

21、c void windowClosing(WindowEvent ee) System.exit(0); ); df.setVisible(true); String s = wen.getText(); try File f = new File( df.getDirectory()+df.getFile(); BufferedWriter bw = new BufferedWriter( new FileWriter (f); bw.write(s , 0 , s.length(); bw.close(); catch(FileNotFoundException fe_) System.o

22、ut.println(file not found); System.exit(0); catch( IOException ie_) System.out.println( IO error); System.exit(0); /剪切 public void cutfile() tempString = wen.getSelectedText(); StringBuffer tmp = new StringBuffer ( wen.getText(); int start = wen.getSelectionStart(); int len = wen.getSelectedText().l

23、ength(); tmp.delete( start , start+len); wen.setText(tmp.toString(); /復(fù)制 public void copyfile() tempString = wen.getSelectedText(); /粘貼 public void castfile() StringBuffer tmp = new StringBuffer ( wen.getText(); /得到要粘貼的位置 int start = wen.getSelectionStart(); tmp.insert(start , tempString); /用新文本設(shè)置原文本 wen.setText(tmp.toString(); /刪除 public void deletefile() StringBuffer tmp = new StringBuffer ( wen

溫馨提示

  • 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ì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論