




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、Java課程設(shè)計報告 題 目: 文本編輯器 班 級: 學 號: 姓 名: 成 績: 日期: 年 月 日目 錄一、綜合設(shè)計的目的與要求 3二、綜合設(shè)計正文31.系統(tǒng)分析31.1系統(tǒng)開發(fā)背景、開發(fā)范圍、建設(shè)目標與必要性開發(fā)31.2需求分析32.系統(tǒng)設(shè)計32.1功能設(shè)計32.2系統(tǒng)運行環(huán)境與開發(fā)工具43 .系統(tǒng)實施43.1源程序43.2. 系統(tǒng)測試及部分截圖12三、綜合設(shè)計總結(jié)或結(jié)論13四、參考文獻13文本編輯器一、綜合設(shè)計的目的與要求要求在學生能夠較熟練使用java程序設(shè)計語言進行軟件代碼的編寫,同時還要具備較好的項目分析的能力,加深對相關(guān)課程基本內(nèi)容的理解。同時,在程序設(shè)計方法以及上機操作等基本
2、技能和科學作風方面受到比較系統(tǒng)的練習。二、綜合設(shè)計正文1 系統(tǒng)分析1.1系統(tǒng)開發(fā)背景、開發(fā)范圍、建設(shè)目標與必要性隨著計算機科學日漸成熟,其強大的功能已為人們深刻認識,它已進入人類社會的各個領(lǐng)域并發(fā)揮著越來越重要的作用。當然對文本編輯操作仍然占據(jù)著重要地位,記事本是簡單便捷的文本編輯器,可實現(xiàn)對文本編輯操作的基本功能。1.2需求分析程序設(shè)計主要分為兩大部分:簡單GUI設(shè)計和程序功能設(shè)計。通過GUI設(shè)計實現(xiàn)圖形用戶界面,提供圖形菜單,方便用戶操作。使用Java語言編寫一個能夠?qū)斎胛淖诌M行操作,具有合理的界面,能夠在界面中實現(xiàn)右鍵快捷方式,對文檔內(nèi)容進行編輯操作,并且能夠順利退出的程序。通過設(shè)計和
3、實現(xiàn)一個具有基本功能的文本編輯器,提高我們對Java語言設(shè)計的掌握能力,理論聯(lián)系實際,進一步提高軟件開發(fā)技術(shù),從而培養(yǎng)我們分析、解決問題的能力。2 系統(tǒng)設(shè)計2.1功能設(shè)計根據(jù)系統(tǒng)自帶的文檔編輯器的特征設(shè)計,包括如下的功能模塊:一、 整體結(jié)構(gòu)框架包括:菜單欄和文檔編輯區(qū)二、 每個框架分別包含不同的子框架,各個模塊的具體框架:1.菜單欄:文件、編輯、工具、幫助2.菜單欄中各個子菜單功能文件:新建、打開、保存、另存為、退出編輯:剪切、復制、粘貼 工具: 查找、替換 3.子菜單功能的實現(xiàn)主要的幾個功能介紹1) 打開與另存為:兩個窗體調(diào)用系統(tǒng)函數(shù)直接利用,注意格式的選擇2) 查找:查找內(nèi)容、查找、查找下
4、一個4文本編輯區(qū)監(jiān)視文本內(nèi)容是否改變、監(jiān)聽光標所在位置 2.2系統(tǒng)運行環(huán)境與開發(fā)工具開發(fā)環(huán)境與工具:jdk2.0 Eclipse SDK3 系統(tǒng)實施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(普通); /定義菜單項 JMenuItem xin=new JMenuItem(新建); JMenuItem open=new JMenuItem(打開); JMenuItem save=new JMenuItem(保存 ); JMenuItem lsave=new JMenuItem(另存為); JMenuItem tui=new JMenuI
6、tem(退出); JMenuItem cut=new JMenuItem(剪切 ); JMenuItem copy=new JMenuItem(復制); JMenuItem cast=new JMenuItem(粘貼); JMenuItem delete=new JMenuItem(刪除 ); JMenuItem b=new JMenuItem(粗體); JMenuItem c=new JMenuItem(斜體);TxtEditor() super (文本編輯器);/對話框 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)和你對話 ,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);/);/滾動條 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)聽器 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); /重寫方法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 = ; /打開 public void openfile() String fileName = null; FileDialog df = new FileDialog(this,打開文件,FileDialog.LOAD); df.setVisible(true); /建立新文件 File f = new File( df.getDirectory()+df.getFile() ); /得到文
16、件名 fileName = df.getDirectory()+df.getFile(); /用此文件的長度建立一個字符數(shù)組 (特別標注) 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)保存過 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(); /復制 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. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 【正版授權(quán)】 ISO 16828:2025 EN Non-destructive testing - Ultrasonic testing - Time-of-flight diffraction technique for detection and sizing of discontinuities
- 多功能城市水系統(tǒng)的優(yōu)化與綜合利用
- 2025至2030全球及中國零售業(yè)務(wù)管理軟件行業(yè)發(fā)展趨勢分析與未來投資戰(zhàn)略咨詢研究報告
- 影視后期制作專業(yè)發(fā)展規(guī)劃
- 固態(tài)電池漸行漸近、新技術(shù)及工藝持續(xù)涌現(xiàn)
- 2025至2030國內(nèi)生物飼料行業(yè)發(fā)展趨勢分析與未來投資戰(zhàn)略咨詢研究報告
- 2025至2030全球及中國聲控燈行業(yè)產(chǎn)業(yè)運行態(tài)勢及投資規(guī)劃深度研究報告
- 2025至2030中國自行式吊桿升降機行業(yè)產(chǎn)業(yè)運行態(tài)勢及投資規(guī)劃深度研究報告
- 2025至2030中國自定義程序托盤行業(yè)市場占有率及投資前景評估規(guī)劃報告
- 2025至2030中國自動絲網(wǎng)印刷行業(yè)產(chǎn)業(yè)運行態(tài)勢及投資規(guī)劃深度研究報告
- 2025年中國LTCC技術(shù)行業(yè)市場現(xiàn)狀、前景分析研究報告(智研咨詢發(fā)布)
- 租賃住房培訓課件下載
- 房管員試題資料
- 2025至2030中國扭蛋機行業(yè)市場發(fā)展現(xiàn)狀及商業(yè)模式與投融資戰(zhàn)略報告
- 2024年蘇州昆山國創(chuàng)投資集團有限公司招聘筆試真題
- DL∕T 5161.5-2018 電氣裝置安裝工程質(zhì)量檢驗及評定規(guī)程 第5部分:電纜線路施工質(zhì)量檢驗
- 湖北武漢洪山區(qū)招考聘用社區(qū)干事235人模擬檢測試卷【共1000題含答案解析】
- IPQC技能培訓
- 2022年(詳細版)高中數(shù)學學業(yè)水平考試知識點
- 常用樂高零件清單
- 蛋糕制作工藝課件(PPT81張)
評論
0/150
提交評論