版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、-. z.期末考察大作業(yè)任務(wù)書課程名稱: Java語言程序設(shè)計設(shè)計實驗 題 目: 簡單記事本的設(shè)計與實現(xiàn) 學(xué) 院: 管理學(xué)院 系: 信息管理系 專業(yè)班級:學(xué) 號: 學(xué)生*: 起訖日期:2015-09-01至2015-12-31 課任教師: 郭路生 學(xué)院審核簽名:審核日期:實驗內(nèi)容 完成一個簡單的記事本程序。實驗要求 1. 實現(xiàn)一個記事本窗口,能夠處理關(guān)閉處理窗口事件。 2. 記事本可進展文本編輯 3記事本具有菜單。 4. 具有保存和翻開功能。 5. 具有字體大小、風(fēng)格等功能 6. 具有復(fù)制、粘貼功能可選項主要儀器設(shè)備及耗材 計算機、eclipse四、主要參考資料 1. 網(wǎng)絡(luò)教學(xué)臺平教材材料列出
2、的資料 2. 教材及實驗指導(dǎo) 3. 教師演示的視頻 4. 網(wǎng)絡(luò)上相關(guān)資料實驗步驟 1、程序代碼截圖程序源代碼文本版import java.awt.event.*;import java.awt.*; import java.io.*;import java*.swing.*;publicclassMyJnpe*tends Frame implements ActionListener /主界面設(shè)置 Menu wenjian = new Menu(文件); Menu geshi = new Menu(格式); Menu help = new Menu(幫助); MenuBar bar = new
3、 MenuBar(); MenuItem dakai = new MenuItem(翻開); MenuItem *injian = newMenuItem(新建); MenuItem baocun = new MenuItem(保存); MenuItem tuichu = new MenuItem(退出); MenuItem ziti*uanz= new MenuItem(字體選擇); MenuItem lingcunwei = new MenuItem(另存為); MenuItem guanyu = new MenuItem(關(guān)于記事本); Te*tAreabianjiqu = new Te
4、*tArea();public MyJnp()super(記事本);bar.add(wenjian);bar.add(geshi);bar.add(help); wenjian.add(*injian);wenjian.add(dakai);wenjian.add(baocun);wenjian.add(lingcunwei);wenjian.add(tuichu);geshi.add(ziti*uanz);help.add(guanyu); add(bianjiqu); setMenuBar(bar); setVisible(true); setBounds(200,100,800,600)
5、; addWindowListener(new WindowAdapter() publicvoid windowClosing(WindowEvent e)System.e*it(0); ); String path; publicvoid addActionListener() /添加事件監(jiān)聽 dakai.addActionListener(this);tuichu.addActionListener(this);*injian.addActionListener(this); baocun.addActionListener(this);lingcunwei.addActionListe
6、ner(this);guanyu.addActionListener(this);ziti*uanz.addActionListener(this); publicvoid actionPerformed(ActionEvent e) /事件處理 if(e.getSource()= tuichu) System.e*it(0);elseif(e.getSource()=dakai) dakaiwenjian temp = new dakaiwenjian();bianjiqu.setTe*t(temp.getData(); elseif(e.getSource()=*injian) bianj
7、iqu.setTe*t(); path=null; elseif(e.getSource()= baocun) if(path=null) String s = bianjiqu.getTe*t(); baocunwenjian wen = new baocunwenjian(); wen.saveData(s);path=wen.getPath(); else baoc bao = new baoc(path); String s = bianjiqu.getTe*t(); bao.saveData(s); elseif(e.getSource()=guanyu) JOptionPane.s
8、howMessageDialog(null, 信管131班 6104113035 郝君,幫助, JOptionPane.INFORMATION_MESSAGE); elseif(e.getSource()=lingcunwei) String s = bianjiqu.getTe*t();new baocunwenjian().saveData(s); elseif(e.getSource()=ziti*uanz) new ziti(bianjiqu); publicstaticvoid main(String args) new MyJnp().addActionListener(); cl
9、ass dakaiwenjian /翻開文件得到字符串并在getData方法中返回字符串 BufferedReader temp; String data=; public dakaiwenjian() try FileDialog s = new FileDialog(new Frame(),翻開,FileDialog.LOAD); s.setVisible(true); String path1 =s.getDirectory()+s.getFile();temp = new BufferedReader(new FileReader(path1); String aline; while
10、(aline=temp.readLine()!=null)data= data+aline+n;temp.close(); catch(E*ception e )System.out.println(翻開失敗); public String getData()returndata; class baocunwenjian /第一次保存和另存為調(diào)用的類 BufferedWriter bw ; String teamp;public baocunwenjian() try FileDialog s = new FileDialog(new Frame(),保存,FileDialog.SAVE);
11、s.setVisible(true);teamp= s.getDirectory()+s.getFile();bw= new BufferedWriter(new FileWriter(teamp); catch(E*ception e)System.out.println(保存失敗); public String getPath() returnteamp; publicvoid saveData(String temp1) trybw.write(temp1);bw.close(); catch(E*ception e)System.out.println(保存失敗); class bao
12、c /屢次保存類 BufferedWriter bw ; String teamp;public baoc(String teamp) try this.teamp= teamp; bw= new BufferedWriter(new FileWriter(teamp); catch(E*ception e)System.out.println(保存失敗); publicvoid saveData(String temp1) trybw.write(temp1);bw.close(); catch(E*ception e)System.out.println(保存失敗); classzitie
13、*tends Dialog implements ActionListener /字體設(shè)置類 intsty=0;intsize=0; Label ys ; Label sz; Panel pan1 = new Panel(); Panel pan2 = new Panel(); Te*tField yangshi ; Te*tField da*iao; Font s; Button queding ; Te*tArea ta; public ziti(Te*tArea ta)super(new Frame(),字體設(shè)置);this.ta=ta;queding= new Button(確定);y
14、angshi= new Te*tField(5);da*iao = new Te*tField(5); ys = new Label(樣式:(請輸入正整數(shù));sz = new Label(大?。赫堓斎胝麛?shù));pan1.add(ys);pan1.add(yangshi);pan2.add(sz);pan2.add(da*iao);pan2.add(queding); add(pan1,BorderLayout.NORTH); add(pan2,BorderLayout.SOUTH);queding.addActionListener(this); setVisible(true); setBo
15、unds(200,200,300,100); setResizable(false); addWindowListener(new WindowAdapter() publicvoid windowClosing(WindowEvent e) ziti.this.dispose(); ); publicvoid actionPerformed(ActionEvent e ) /字體設(shè)置處理 String k; if(e.getSource()=queding)if(k=yangshi.getTe*t()!=null) sty=Integer.valueOf(k); if(k=da*iao.getTe*t()!=null) size= Integer.valueOf(k); if(sty=0&sty=0&size=100) s = new Font(myfont,sty,size); ta.setFont(s); ziti.this.dispose(); 2、程序運行截圖1運行軟件記事本能夠處
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 消費券發(fā)放協(xié)議書
- 純電車保價協(xié)議書
- 交房結(jié)算協(xié)議書
- 中韓薩德協(xié)議書
- 醫(yī)療器械注冊專員面試題及答案解析
- 零售業(yè)財務(wù)經(jīng)理人面試題及答案參考
- 軟件測試工程師的招聘面試問題與解答策略
- 金融行業(yè)產(chǎn)品經(jīng)理面試寶典及答案
- 資深項目經(jīng)理團隊管理能力評估面試題及答案
- 合規(guī)助理面試常見問題及答案解析
- 6第六章 項目管理架構(gòu)
- 2025年全新中醫(yī)藥學(xué)概論試題與答案
- 2026云上(貴州)數(shù)據(jù)開發(fā)有限公司第一次社會招聘18人考試筆試備考題庫及答案解析
- 2026年湖南電子科技職業(yè)學(xué)院單招職業(yè)技能考試題庫及參考答案詳解
- 2025秋小學(xué)湘科版(新教材)科學(xué)三年級上冊知識點及期末測試卷及答案
- 裝修工賠償協(xié)議書
- 2026年稅務(wù)風(fēng)險培訓(xùn)
- 2025重慶兩江新區(qū)公安機關(guān)輔警招聘56人備考題庫含答案詳解(完整版)
- 負債整合委托協(xié)議書
- 2026年上海市各區(qū)高三語文一模試題匯編之積累運用(學(xué)生版)
- 小學(xué)科學(xué)探究課程教案
評論
0/150
提交評論