![java記事本綜合實驗報告_第1頁](http://file4.renrendoc.com/view/da3a2120b0971bf59f4868ca6e46a9ea/da3a2120b0971bf59f4868ca6e46a9ea1.gif)
![java記事本綜合實驗報告_第2頁](http://file4.renrendoc.com/view/da3a2120b0971bf59f4868ca6e46a9ea/da3a2120b0971bf59f4868ca6e46a9ea2.gif)
![java記事本綜合實驗報告_第3頁](http://file4.renrendoc.com/view/da3a2120b0971bf59f4868ca6e46a9ea/da3a2120b0971bf59f4868ca6e46a9ea3.gif)
![java記事本綜合實驗報告_第4頁](http://file4.renrendoc.com/view/da3a2120b0971bf59f4868ca6e46a9ea/da3a2120b0971bf59f4868ca6e46a9ea4.gif)
![java記事本綜合實驗報告_第5頁](http://file4.renrendoc.com/view/da3a2120b0971bf59f4868ca6e46a9ea/da3a2120b0971bf59f4868ca6e46a9ea5.gif)
版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
...wd......wd......wd...華北科技學院計算機學院課程綜合作業(yè)實驗報告課程名稱Java大學實用教程實驗學期2012至2013學年第一學期學生所在系部計算機學院年級2011專業(yè)班級信管B11-x學生姓名xxx學號xxxxxxxxxxx任課教師王養(yǎng)廷實驗成績計算機學院制《JAVA程序設計》課程綜合作業(yè)實驗報告開課實驗室:根基四2012年12月20日實驗題目用java編寫簡單記事本實驗目的掌握面向對象程序設計根本要素〔封裝、繼承、多態(tài)〕掌握JAVA語言常用類包及其常用方法和JAVA語言根本語法掌握基于AWT的圖形用戶界面設計常用標準控件的使用,如標簽、按鈕、菜單、文本框、單項選擇按鈕、滾動條等。事件處理機制掌握布局、對話框的使用掌握發(fā)布JAVA應用程序設備與環(huán)境硬件:多媒體計算機軟件:Windows2000以上的操作系統(tǒng)、JAVA集成開發(fā)環(huán)境實驗內容1.完成記事本的需求分析。2.記事本的總體設計,列出主要的類和類間關系。3.列出具體的實現(xiàn)代碼。4.寫出程序的實現(xiàn)細節(jié),主要得功能界面,實現(xiàn)說明。5.寫出總結和評價。四、實驗結果及分析1.實驗分析本程序是一個簡單的記事本程序,其主要構造參照了Windows操作系統(tǒng)的記事本工具。能夠實現(xiàn)一些根本功能,主要有:具有編輯界面,能夠實現(xiàn)文本的輸入、刪除等根本功能。具有菜單條,包含三個主菜單:文件、編輯、幫助。各個主菜單分別擁有其菜單項選擇項。文件主菜單含有新建、翻開、保存、另存為、退出五個菜單項選擇項;編輯主菜單含有剪切、粘貼、復制、全選四個菜單項選擇項。幫助主菜單好友關于記事本信息的菜單項選擇項,主要記錄了記事本文件的根本信息。各個菜單項選擇項能夠實現(xiàn)其對應的功能。實現(xiàn)剪切、復制、粘貼、全選即編輯菜單的鼠標跳出菜單功能。各功能具有快捷鍵。2.程序設計思想①首先設計出整個記事本的主體框架,添加菜單欄〔JMenu〕,添加菜單項選擇項〔JMenuItem〕。這局部應用到了Container、JMenuBar、JMenu、JMenuItem的構造方法,實現(xiàn)對記事本的根本頁面設計。在頁面中添加編輯局域,應用了JTextArea的構造方法。實現(xiàn)各個菜單項選擇項的功能。在具體的功能實現(xiàn)中,為每一個功能設計了一個類,通過監(jiān)聽調用類方法實現(xiàn)所需要實現(xiàn)的功能。程序中的類以及它們之間的關系:本程序總共含有9個類:Notebook()主類:他實現(xiàn)了記事本的根本框架構造,以及對記事本各個功能的監(jiān)聽,并且調用各個功能的類方法。在Notebook()中,參加了編輯菜單的彈出菜單功能。在Notebook()主類中,通過事件監(jiān)聽調用了剪切、復制、保存等功能的類方法:NewActionListener〔〕:實現(xiàn)“新建〞功能的類SaveActionListener〔〕:實現(xiàn)“保存〞功能的類OpenActionListener〔〕:實現(xiàn)“翻開〞功能的類ExitActionListener〔〕:實現(xiàn)“退出〞功能的類CutActionListener〔〕:實現(xiàn)“剪切〞功能的類CopyActionListener〔〕:實現(xiàn)“粘貼〞功能的類SallActionListener〔〕:實現(xiàn)“全選〞功能的類AbouthActionListener〔〕:實現(xiàn)“關于〞功能的類添加事件監(jiān)聽Notebook〔〕添加事件監(jiān)聽Notebook〔〕初始化界面組件菜單欄文件編輯幫助新建翻開保存退出剪切復制粘貼全選關于另存文字輸入?yún)^(qū)文字輸入?yún)^(qū)4.程序代碼importjava.awt.*;importjava.awt.event.*;importjava.io.*;importjavax.swing.*;publicclassMyNotebook{publicstaticvoidmain(Stringargs[]){newNotebook();}}//Notebook()主類:classNotebookextendsJFrame{ Containercontainer; JFileChooserfc=newJFileChooser();Filefile=null;JMenuBarmb;JMenufileMenu,editMenu,helpMenu;JMenuItemnewItem,openItem,saveItem,saveasItem,exitItem,cutItem,copyItem,pasteItem,sallItem,aboutItem;JTextAreajta;JPopupMenupopUpMenu;publicNotebook() {//記事本主界面設計程序// setTitle("記事本"); container=this.getContentPane(); container.setLayout(newBorderLayout()); jta=newJTextArea(); container.add(jta); setVisible(true); setSize(650,450); mb=newJMenuBar(); setJMenuBar(mb);//文件菜單及其菜單項選擇項的程序設計// fileMenu=newJMenu("文件"); newItem=newJMenuItem("新建");//設置快捷鍵// newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK));//設置“新建〞事件監(jiān)聽// newItem.addActionListener(newNewActionListener()); fileMenu.add(newItem); fileMenu.addSeparator(); openItem=newJMenuItem("翻開"); openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,ActionEvent.CTRL_MASK)); openItem.addActionListener(newOpenActionListener()); fileMenu.add(openItem); fileMenu.addSeparator(); saveItem=newJMenuItem("保存"); saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK)); saveItem.addActionListener(newSaveActionListener()); fileMenu.add(saveItem); fileMenu.addSeparator(); saveasItem=newJMenuItem("另存為"); saveasItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,ActionEvent.CTRL_MASK)); saveasItem.addActionListener(newSaveActionListener()); fileMenu.add(saveasItem); fileMenu.addSeparator(); exitItem=newJMenuItem("退出"); exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,ActionEvent.CTRL_MASK)); exitItem.addActionListener(newExitActionListener()); fileMenu.add(exitItem); mb.add(fileMenu); //編輯菜單欄及其菜單項選擇項程序設計// editMenu=newJMenu("編輯"); cutItem=newJMenuItem("剪切"); cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,ActionEvent.CTRL_MASK)); cutItem.addActionListener(newCutActionListener()); editMenu.add(cutItem); editMenu.addSeparator(); copyItem=newJMenuItem("復制"); copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK)); copyItem.addActionListener(newCopyActionListener()); editMenu.add(copyItem); editMenu.addSeparator(); pasteItem=newJMenuItem("粘貼"); pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK)); pasteItem.addActionListener(newPasteActionListener()); editMenu.add(pasteItem); editMenu.addSeparator(); sallItem=newJMenuItem("全選"); sallItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M,ActionEvent.CTRL_MASK)); sallItem.addActionListener(newSallActionListener()); editMenu.add(sallItem); mb.add(editMenu);//幫助菜單欄及其菜單項選擇項程序設計// helpMenu=newJMenu("幫助"); aboutItem=newJMenuItem("關于記事本"); aboutItem.addActionListener(newAbouthActionListener()); helpMenu.add(aboutItem); mb.add(helpMenu); //編輯菜單的鼠標監(jiān)聽及其彈出菜單的功能設計// popUpMenu=editMenu.getPopupMenu(); jta.addMouseListener(newMouseAdapter(){publicvoidmouseReleased(MouseEvente){if(e.getButton()==MouseEvent.BUTTON3)popUpMenu.show(editMenu,e.getX(),e.getY());}publicvoidmouseClicked(MouseEvente){if(e.getButton()==MouseEvent.BUTTON1)popUpMenu.setVisible(false);}});} //“新建〞功能的實現(xiàn)// classNewActionListenerimplementsActionListener{ publicvoidactionPerformed(ActionEvente){ jta.setText(""); file=null; } } //“保存功能的實現(xiàn)〞// classSaveActionListenerimplementsActionListener { publicvoidactionPerformed(ActionEvente){ if(file!=null)fc.setSelectedFile(file); intreturnVal=fc.showSaveDialog(Notebook.this); if(returnVal==JFileChooser.APPROVE_OPTION){ file=fc.getSelectedFile(); saving();} } voidsaving(){ try{ FileWriterWritef=newFileWriter(file); Writef.write(jta.getText()); Writef.close(); } catch(Exceptione){e.printStackTrace();} } }//“翻開〞功能的實現(xiàn)// classOpenActionListenerimplementsActionListener { publicvoidactionPerformed(ActionEvente){ if(file!=null)fc.setSelectedFile(file);intreturnVal=fc.showOpenDialog(Notebook.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=fc.getSelectedFile();unfold();}}voidunfold(){try{FileReaderReadf=newFileReader(file);intlen=(int)file.length();char[]buffer=newchar[len];Readf.read(buffer,0,len);Readf.close();jta.setText(newString(buffer));}catch(Exceptione){e.printStackTrace();}}}//“退出〞功能的實現(xiàn)// classExitActionListenerimplementsActionListener { publicvoidactionPerformed(ActionEvente){ setVisible(false); dispose(); System.exit(0); } }//“剪切〞功能的實現(xiàn)// classCutActionListenerimplementsActionListener { publicvoidactionPerformed(ActionEvente){ jta.cut(); } }//“復制〞功能的實現(xiàn)// classCopyActionListenerimplementsActionListener { publicvoidactionPerformed(ActionEvente){ jta.copy(); } }//“粘貼〞功能的實現(xiàn)// classPasteActionListenerimplementsActionListener { publicvoidactionPerformed(ActionEvente){ jta.paste(); } } //“全選〞功能的實現(xiàn)// classSallActionListenerimplementsActionListener { publicvoidactionPerformed(ActionEvente){ jta.setSelectionStart(0); jta.setSelectionEnd(jta.getText().length()); } } //“關于〞功能的實現(xiàn)// classAbouthActionListenerimplements
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年智能化高架活動地板項目可行性研究報告
- 2025年排水閥門項目可行性研究報告
- 2025年大紅描金粉蠟箋項目可行性研究報告
- 2025年壓片機項目可行性研究報告
- 2025年全粒面填充項目可行性研究報告
- 2025年PVC可調電容項目可行性研究報告
- 2025至2030年中國陶瓷纖維澆注料數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國轉動計數(shù)器數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年中國落地通風柜數(shù)據(jù)監(jiān)測研究報告
- 2025至2030年樺木皮項目投資價值分析報告
- 測繪保密協(xié)議書保密協(xié)議(2024版)
- 原發(fā)性血小板減少性紫癜患者的生活質量
- HG20202-2014 脫脂工程施工及驗收規(guī)范
- 基層醫(yī)療機構公共衛(wèi)生健康教育工作手冊(各類表格模板)
- 2024版《保密法》培訓課件
- 2024年內蒙古中考地理生物試卷(含答案)
- LY/T 3378-2024木蠟油地板
- 元宵節(jié)猜燈謎 11
- 施工現(xiàn)場視頻監(jiān)控系統(tǒng)施工方案
- (正式版)JTT 1495-2024 公路水運危險性較大工程安全專項施工方案審查規(guī)程
- 2024年演出經(jīng)紀人考試必背1000題一套
評論
0/150
提交評論