java記事本實驗報告_第1頁
java記事本實驗報告_第2頁
java記事本實驗報告_第3頁
java記事本實驗報告_第4頁
已閱讀5頁,還剩9頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

1、期末考查大作業(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. 記事本可進(jìn)行文本編輯3記事本具有菜單。4. 具有保存和打開功能。5. 具有字體大小、風(fēng)格等功能6. 具有復(fù)制、粘貼功能(可選項)三、主要儀器設(shè)備及耗材計算機(jī)、 eclipse四、主要參考資料1. 網(wǎng)絡(luò)教學(xué)臺平教材材料列出的資料2. 教材及實

2、驗指導(dǎo)3. 老師演示的視頻4. 網(wǎng)絡(luò)上相關(guān)資料五、實驗步驟1、程序代碼截圖2精選文庫3精選文庫程序源代碼(文本版)importimportimportimportpublicclassMyJnpextendsFrameimplementsActionListener/主界面設(shè)置Menuwenjian=new Menu(" 文件 " );Menugeshi=new Menu(" 格式 " );Menuhelp=new Menu(" 幫助 " );MenuBarbar=new MenuBar();MenuItemdakai=new Men

3、uItem(" 打開 " );MenuItemxinjian=new MenuItem(" 新建 " );MenuItembaocun=new MenuItem(" 保存 " );MenuItemtuichu=new MenuItem(" 退出 " );MenuItemzitixuanz=new MenuItem(" 字體選擇 " );MenuItemlingcunwei=new MenuItem(" 另存為 " );MenuItemguanyu=new MenuItem(&

4、quot; 關(guān)于記事本" );TextAreabianjiqu=new TextArea();publicMyJnp()super( " 記事本 " );bar .add(wenjian);bar .add(geshi);bar .add(help);wenjian.add(xinjian);wenjian.add(dakai);wenjian.add(baocun);wenjian.add(lingcunwei);wenjian.add(tuichu);geshi.add(zitixuanz);help.add(guanyu);add(bianjiqu);set

5、MenuBar(bar );setVisible(true);setBounds(200,100,800,600);addWindowListener(new WindowAdapter()publicvoidwindowClosing(WindowEvent e)System.exit(0); );4精選文庫Stringpath;publicvoidaddActionListener()/添加事件監(jiān)聽dakai.addActionListener(this);tuichu.addActionListener(this);xinjian.addActionListener(this);baoc

6、un.addActionListener(this);lingcunwei.addActionListener(this);guanyu.addActionListener(this);zitixuanz.addActionListener(this);publicvoidactionPerformed(ActionEvent e)/事件處理if(e.getSource()=tuichu)System.exit(0);elseif(e.getSource()=dakai)dakaiwenjian temp =new dakaiwenjian();bianjiqu.setText(temp.ge

7、tData();elseif(e.getSource()=xinjian)bianjiqu.setText("" );path=null;elseif(e.getSource()=baocun)if( path= null)String s =bianjiqu.getText();baocunwenjian wen =new baocunwenjian();wen.saveData(s);path=wen.getPath();elsebaoc bao =new baoc(path);String s =bianjiqu.getText();bao.saveData(s);5

8、精選文庫elseif(e.getSource()=guanyu )JOptionPane.showMessageDialog( null , " 信管 131班 6104113035郝君" , " 幫助 " , JOptionPane.INFORMATION_MESSAGE );elseif(e.getSource()=lingcunwei)String s =bianjiqu.getText();new baocunwenjian().saveData(s);elseif(e.getSource()=zitixuanz)new ziti(bianjiq

9、u);publicstaticvoidmain(String args)new MyJnp().addActionListener();classdakaiwenjian/打開文件得到字符串并在getData方法中返回字符串BufferedReadertemp ;Stringdata= "" ;publicdakaiwenjian()tryFileDialog s =new FileDialog(new Frame()," 打開 " ,FileDialog.LOAD);s.setVisible(true);String path1 =s.getDirec

10、tory()+""+s.getFile();temp=new BufferedReader(new FileReader(path1);String aline;while(aline=temp .readLine()!=null)data=data+aline+'n'temp .close();catch(Exception e )System.out .println(" 打開失敗 " );publicString getData()returndata;6精選文庫classbaocunwenjian/第一次保存和另存為調(diào)用的類Buf

11、feredWriterbw ;Stringteamp ;publicbaocunwenjian()tryFileDialogs =new FileDialog(new Frame()," 保存 " ,FileDialog.SAVE);s.setVisible(true);teamp = s.getDirectory()+s.getFile();bw=new BufferedWriter(new FileWriter(teamp );catch(Exception e)System.out .println(" 保存失敗 " );publicString

12、getPath()returnteamp ;publicvoidsaveData(String temp1)trybw .write(temp1);bw.close();catch(Exception e)System.out .println(" 保存失敗 " );classbaoc /多次保存類BufferedWriterbw ;Stringteamp ;publicbaoc(String teamp)trythis. teamp = teamp;bw=new BufferedWriter(new FileWriter(teamp);catch(Exception e)

13、System.out .println(" 保存失敗 " );publicvoidsaveData(String temp1)trybw .write(temp1);bw.close();catch(Exception e)System.out .println(" 保存失敗 " );7精選文庫classzitiextendsDialogimplementsActionListener/字體設(shè)置類intsty=0;intsize=0;Labelys ;Labelsz ;Panelpan1=new Panel();Panelpan2=new Panel()

14、;TextFieldyangshi;TextFielddaxiao;Fonts ;Buttonqueding;TextAreata ;publicziti(TextArea ta)super( new Frame()," 字體設(shè)置 " );this. ta =ta;queding=new Button(" 確定 " );yangshi=new TextField(5);daxiao=new TextField(5);ys =new Label(" 樣式: ( 請輸入正整數(shù))" );sz =new Label(" 大?。海ㄕ堓?/p>

15、入正整數(shù))" );pan1 .add(ys );pan1 .add(yangshi);pan2 .add(sz );pan2 .add(daxiao);pan2 .add(queding);add(pan1 ,BorderLayout.NORTH);add(pan2 ,BorderLayout.SOUTH);queding.addActionListener(this);setVisible(true);setBounds(200,200,300,100);setResizable(false);addWindowListener(new WindowAdapter()publicv

16、oidwindowClosing(WindowEvent e)ziti.this.dispose(););publicvoidactionPerformed(ActionEvente )/字體設(shè)置處理String k;if(e.getSource()=queding)8精選文庫if(k=yangshi.getText()!=null)sty=Integer.valueOf(k);if(k=daxiao.getText()!=null)size= Integer.valueOf(k);if( sty>=0&& sty<=100&& size>=0&& size<=100)s =new Font("myfont", sty, size);ta .setFont(s );ziti.this.dispose();2、程序運(yùn)行截圖( 1)運(yùn)行軟件記事本能夠處理關(guān)閉處理窗口事件9精選文庫記事本中可以進(jìn)

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論