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

下載本文檔

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

文檔簡(jiǎn)介

1、一 實(shí)驗(yàn)?zāi)康募由顚W(xué)生對(duì)課堂講授內(nèi)容的理解,從計(jì)算機(jī)語(yǔ)言的基本概念、程序設(shè)計(jì)的基本方法、語(yǔ)法規(guī)則等方面加深理解,打好程序設(shè)計(jì)、開(kāi)發(fā)軟件的良好基礎(chǔ)。在上機(jī)實(shí)驗(yàn)中,提高學(xué)生對(duì)Java 語(yǔ)言各部分內(nèi)容的綜合使用能力,逐步掌握 Java 語(yǔ)言程序設(shè)計(jì)的規(guī)律與技巧。在對(duì) Java程序的調(diào)試過(guò)程中, 提高學(xué)生分析程序中出現(xiàn)的錯(cuò)誤和排除這些錯(cuò)誤的能力。通過(guò)上機(jī)實(shí)踐,加深學(xué)生對(duì)計(jì)算機(jī)軟件運(yùn)行環(huán)境,以及對(duì)操作系統(tǒng)與計(jì)算機(jī)語(yǔ)言支持系統(tǒng)相互關(guān)系的了解。二、實(shí)驗(yàn)要求(1) 問(wèn)題描述準(zhǔn)確、規(guī)范;(2) 程序結(jié)構(gòu)合理,調(diào)試數(shù)據(jù)準(zhǔn)確、有代表性;(3) 界面布局整齊,人機(jī)交互方便;(4) 輸出結(jié)果正確;(5) 正確撰寫(xiě)實(shí)驗(yàn)報(bào)告

2、。三、設(shè)計(jì)內(nèi)容1、計(jì)算器計(jì)算器要有GUI 界面,用戶(hù)可以輸入所需計(jì)算的數(shù)值,可以進(jìn)行加、減、乘、除四種最基本的運(yùn)算和混合運(yùn)算,可以求一個(gè)數(shù)值的平方及倒數(shù),可以進(jìn)行階乘運(yùn)算, 要能運(yùn)算小數(shù),并且不會(huì)產(chǎn)生精度損失,在必要情況下,可以進(jìn)行四舍五入的運(yùn)算。允許正負(fù)數(shù)間的運(yùn)算。要求使用Applet實(shí)現(xiàn)該計(jì)算器,當(dāng)用瀏覽器運(yùn)行程序時(shí),點(diǎn)擊網(wǎng)頁(yè)中的按鈕,則計(jì)算器彈出,浮在網(wǎng)頁(yè)上,再次點(diǎn)擊按鈕時(shí),計(jì)算器消失。2、文本編輯器可以設(shè)置文本的字體、大小、顏色等基本參數(shù),可以讀取計(jì)算機(jī)中TXT文件,可以生成一個(gè)新的TXT文件。其他功能參照windows 的文本編輯器。1四實(shí)驗(yàn)步驟(1) 上機(jī)實(shí)驗(yàn)之前,為課程設(shè)計(jì)的內(nèi)容

3、作好充分準(zhǔn)備。對(duì)每次上機(jī)需要完成的任務(wù)進(jìn)行認(rèn)真的分析, 畫(huà)出程序流程圖, 手工寫(xiě)出符合任務(wù)要求的程序清單, 準(zhǔn)備出調(diào)試程序使用的數(shù)據(jù),以便提高上機(jī)實(shí)驗(yàn)的效率。(2) 按照實(shí)驗(yàn)?zāi)康暮蛯?shí)驗(yàn)內(nèi)容進(jìn)行上機(jī)操作。錄入程序,編譯調(diào)試,反復(fù)修改,直到使程序正常運(yùn)行,得出正確的輸出結(jié)果為止。(3) 根據(jù)實(shí)驗(yàn)結(jié)果,寫(xiě)出實(shí)驗(yàn)報(bào)告。五 . 源代碼及運(yùn)行結(jié)果1計(jì)算器源代碼import java.awt.*;import java.awt.event.*;import java.lang.*;import javax.swing.*;public class jisuanqi extends WindowAdapter

4、/ 創(chuàng)建三個(gè)面板Panel p1 = new Panel();Panel p2 = new Panel();Panel p3 = new Panel();TextField txt;private Button b = new Button21;private String ss = "7", "8", "9", "/","清空 " ,"4", "5", "6", "*","1/x","

5、1", "2","3", "-","平方 ", "0", ".", "=", "+","n!" ,"關(guān)閉 " ;static double a, sum=1;static String s, str ;/定義變量創(chuàng)建對(duì)像/ 創(chuàng)建文本框public static void main(String args)(new jisuanqi().frame();public void frame(

6、)2/ 設(shè)置文本框的名稱(chēng)Frame fm = new Frame("簡(jiǎn)單計(jì)算器 ");for (int i = 0; i <= 20; i+)bi = new Button(ssi);for (int i = 0; i <= 19; i+)p2.add(bi); /創(chuàng)建按鈕并添加到P2/ 按鈕 20 背景色黃色b20.setBackground(Color.yellow);txt = new TextField("");txt.setEditable(false);/不能編輯文本框里面的內(nèi)容txt.setBackground(Color.wh

7、ite);for (int i = 0; i <= 20; i+)bi.addActionListener(new buttonlistener();/添加監(jiān)聽(tīng)器/ 設(shè)置關(guān)閉按鈕b20.addActionListener(new close();fm.addWindowListener(this);p1.setLayout(new BorderLayout();/設(shè)置布局管理器p1.add(txt, "North");/p1面板放到區(qū)域南部p2.setLayout(new GridLayout(4, 5,2,2);/布局:四行五列,間隔為二p2.setBackgrou

8、nd(Color.red);p3.setLayout(new BorderLayout();p3.add(b20);將三個(gè)面板分別放到不同位置fm.add(p1, "North");fm.add(p2, "Center");fm.add(p3, "South");fm.pack();fm.setVisible(true);/都是些窗中設(shè)置添加相關(guān)組件和監(jiān)聽(tīng)器public void windowClosing(WindowEvent e) System.exit(0);/退出系統(tǒng)3class buttonlistener impleme

9、nts ActionListener/ 編寫(xiě)監(jiān)聽(tīng)器事件 通過(guò)按鍵得出給果public void actionPerformed(ActionEvent e)Button btn = (Button) e.getSource();if (btn.getLabel() = "=")jisuan();str = String.valueOf(a);txt.setText(str);/顯示當(dāng)前數(shù)字s = ""/清零else if(btn.getLabel() = "+")/ 設(shè)置一個(gè)方法jisuan();txt.setText("&

10、quot;);s = "+"else if(btn.getLabel() = "-")jisuan();txt.setText("");s = "-"else if(btn.getLabel() = "/")jisuan();txt.setText("");s = "/";4else if(btn.getLabel() = "*")jisuan();txt.setText("");s = "*"e

11、lse if(btn.getLabel()="平方 ")a=Double.parseDouble(txt.getText();a*=a;txt.setText(""+String.valueOf(a);else if(btn.getLabel()="n!")a=Double.parseDouble(txt.getText();sum=1;for (int i=1;i<=a;i+)sum=sum*i;txt.setText(""+String.valueOf(sum);else ifbtn.getLabel()

12、="1/x")a=Double.parseDouble(txt.getText();txt.setText(""+String.valueOf(1/a);elsetxt.setText(txt.getText() + btn.getLabel();if (btn.getLabel() = "清空 ")txt.setText("");public void jisuan() /編寫(xiě)具體計(jì)算方法5if (s = "+")a += Double.parseDouble(txt.getText();el

13、se if (s = "-")a -= Double.parseDouble(txt.getText();else if (s = "*")a *= Double.parseDouble(txt.getText();else if (s = "/")a /= Double.parseDouble(txt.getText();elsea = Double.parseDouble(txt.getText();class close implements ActionListener/ 退出public void actionPerform

14、ed(ActionEvent e)System.exit(0);.2.計(jì)算器運(yùn)行界面(1) 計(jì)算器主界面6( 2)面板的實(shí)現(xiàn)1. 創(chuàng)建三個(gè)面板分別是顯示數(shù)字的面板、按鈕的面板和“關(guān)閉”的面板Panel p1 = new Panel();Panel p2 = new Panel();Panel p3 = new Panel();2. 創(chuàng)建一個(gè)文本框參數(shù)TextField txt;3. 創(chuàng)建一群按鈕參數(shù)并給按鈕賦值private Button b = new Button21;private String ss = "7", "8", "9&quo

15、t;, "/","清空 " ,"4", "5", "6", "*","1/x","1", "2","3", "-","平方 ", "0", ".", "=", "+","n!" ,"關(guān)閉 " ;4. 創(chuàng)建文本框public static v

16、oid main(String args)(new jisuanqi().frame();5. 設(shè)置文本框方法public void frame()/ 設(shè)置文本框的名稱(chēng)Frame fm = new Frame("簡(jiǎn)單計(jì)算器 ");6. 設(shè)置按鈕for (int i = 0; i <= 20; i+)bi = new Button(ssi);7. 設(shè)將按鈕添加到面板for (int i = 0; i <= 19; i+)p2.add(bi); /創(chuàng)建按鈕并添加到P28. 設(shè)置按鈕 20 背景色黃色b20.setBackground(Color.yellow);9.

17、 創(chuàng)建文本框,并規(guī)定不能編輯內(nèi)容和背景為白色txt = new TextField("");txt.setEditable(false);txt.setBackground(Color.white);710. 為按鈕添加監(jiān)聽(tīng)器for (int i = 0; i <= 20; i+)bi.addActionListener(new buttonlistener();/添加監(jiān)聽(tīng)器11. 設(shè)置“關(guān)閉”按鈕可以關(guān)閉界面并設(shè)置監(jiān)聽(tīng)器b20.addActionListener(new close();fm.addWindowListener(this);12. 設(shè)置布局p1.se

18、tLayout(new BorderLayout();/設(shè)置布局管理器p1.add(txt, "North");/p1面板放到區(qū)域南部p2.setLayout(new GridLayout(4, 5,2,2);/布局:四行五列,間隔為二p2.setBackground(Color.red);p3.setLayout(new BorderLayout();p3.add(b20);13. 將三個(gè)面板分別放到不同位置fm.add(p1, "North");fm.add(p2, "Center");fm.add(p3, "South

19、");fm.pack();fm.setVisible(true);/都是些窗中設(shè)置添加相關(guān)組件和監(jiān)聽(tīng)器14. 退出系統(tǒng)public void windowClosing(WindowEvent e)System.exit(0);( 3)將按鈕添加到計(jì)算這個(gè)事件中1. 編寫(xiě)監(jiān)聽(tīng)器事件通過(guò)按鍵得出給果public void actionPerformed(ActionEvent e)/ 將按鈕賦予這個(gè)事件中Button btn = (Button) e.getSource();2. 如果點(diǎn)擊“ =”這個(gè)按鈕,將出現(xiàn)當(dāng)前數(shù)字if (btn.getLabel() = "="

20、;)jisuan();8str = String.valueOf(a);txt.setText(str);/顯示當(dāng)前數(shù)字s = ""/清零3. 如果點(diǎn)擊“ +”“ - ”“ * ”“ / ”分別完成一個(gè)方法并將結(jié)果顯示到文本框 else if(btn.getLabel() = "+")/ 設(shè)置一個(gè)方法jisuan();txt.setText("");s = "+"else if(btn.getLabel() = "-")jisuan();txt.setText("");s =

21、 "-"else if(btn.getLabel() = "/")jisuan();txt.setText("");s = "/";else if(btn.getLabel() = "*")jisuan();txt.setText("");s = "*"4. 如果點(diǎn)擊“平方”則當(dāng)前數(shù)字與原數(shù)字形成即完成相關(guān)方法結(jié)果顯示最終的數(shù)字else if(btn.getLabel()="平方 ")9a=Double.parseDouble(txt.

22、getText();a*=a;txt.setText(""+String.valueOf(a);/ 顯示 a5. 當(dāng)輸入“ n!”,就用 for循環(huán)完成階乘,此方法屬于c 語(yǔ)言基礎(chǔ)方法,不做相關(guān)解釋else if(btn.getLabel()="n!")a=Double.parseDouble(txt.getText();sum=1;/歸一for (int i=1;i<=a;i+)sum=sum*i;txt.setText(""+String.valueOf(sum); /文本框中顯示“sum”的數(shù)值6. 當(dāng)輸入“ 1/x ”時(shí)

23、,顯示 1/a 。 else ifbtn.getLabel()="1/x")a=Double.parseDouble(txt.getText();txt.setText(""+String.valueOf(1/a);7如果輸入“清空”文本框成為空文本框elsetxt.setText(txt.getText() + btn.getLabel();if (btn.getLabel() = "清空 ")txt.setText("");( 4)設(shè)置“ jisuan ”方法1. 編寫(xiě)具體計(jì)算方法其實(shí)這些方法可以放到上面事件的

24、實(shí)現(xiàn)中,從 “平方”,“ n!”,“ 1/x ”就可以看出。但為了程序的美觀和高識(shí)別性,我們傳建一個(gè)方法來(lái)實(shí)現(xiàn)if (s = "+")a += Double.parseDouble(txt.getText();else if (s = "-")a -= Double.parseDouble(txt.getText();else if (s = "*")10a *= Double.parseDouble(txt.getText();else if (s = "/")a /= Double.parseDouble(tx

25、t.getText();elsea = Double.parseDouble(txt.getText();3 文本編輯器 源代碼import java.awt.*;import javax.swing.*;import java.awt.event.*;import javax.swing.event.*;import java.io.*;public class TextEditorpublic static void main(String args)TextFrame frame=new TextFrame(); frame.setDefaultCloseOperation(JFrame

26、.EXIT_ON_CLOSE); frame.show();class TextFrame extends JFrame/ 文件中的參數(shù)File file = null;static String d,k,s;/ 編輯中的參數(shù)String selected,text;/ 格式中的參數(shù)String sizeNames ="5","10","15","20","25","30","35","40","45","

27、50"String colorNames ="黑色 "," 紅色 "," 藍(lán)色 "," 綠色 "," 白色 "," 黃色 "," 粉紅 "String fontNames="宋體 "," 華文行楷 "," 隸書(shū) "," 黑體 "," 仿宋 "," 華文彩云 "," 楷體 "," 方正姚體 "

28、;String styleNames = "粗體 ", "斜體 " ;public TextFrame()/ 設(shè)置文本框大小、名稱(chēng)11setTitle("西西牌文本編輯器");setSize(400,400);addWindowListener(new LogoutAction();filechooser=new JFileChooser();/創(chuàng)建一個(gè)文件選擇器/創(chuàng)建文本區(qū)t1=new JTextArea(0,0);/面板與文本框無(wú)間隙scrollPane=new JScrollPane(t1);/設(shè)置滾動(dòng)條getContentPa

29、ne().add(scrollPane);/ 創(chuàng)建菜單欄menuBar=new JMenuBar();setJMenuBar(menuBar);/ 文件files=new JMenu("文件 (F)");files.setMnemonic('F');/設(shè)置快捷鍵newItem=new JMenuItem("新建 (N)",'N');openItem=new JMenuItem("打開(kāi) (O).",'O');saveItem=new JMenuItem("保存 (S)"

30、,'S');exitItem=new JMenuItem("退出 (E)",'E');/設(shè)置監(jiān)聽(tīng)器newItem.addActionListener(new FileListener();openItem.addActionListener(new FileListener();saveItem.addActionListener(new FileListener();exitItem.addActionListener(new FileListener();/ 設(shè)置加速器newItem.setAccelerator(KeyStroke.ge

31、tKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK);openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK);saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK);/ 添加按鈕到文件菜單欄files.add(newItem);files.add(openItem);files.add(saveItem);files.add(exitIt

32、em);/ 編輯edit=new JMenu("編輯 (E)");edit.setMnemonic('E');/創(chuàng)建菜單項(xiàng)cutItem=new JMenuItem("剪切 (T)");copyItem=new JMenuItem("復(fù)制 (C)");pasteItem=new JMenuItem("粘貼 (P)");12deleteItem=new JMenuItem("刪除 (L)");selectAllItem=new JMenuItem("全選 (A)"

33、;);/設(shè)置加速器cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK);copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK);pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK);deleteItem.setAccelerator(KeyStroke.getKey

34、Stroke(KeyEvent.VK_L,InputEvent.CTRL_MASK);selectAllItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,InputEvent.CTRL_MASK);/ 設(shè)置監(jiān)聽(tīng)器cutItem.addActionListener(new EditListener();copyItem.addActionListener(new EditListener();pasteItem.addActionListener(new EditListener();deleteItem.addActionList

35、ener(new EditListener();selectAllItem.addActionListener(new EditListener();/ 添加按鈕到“編輯”菜單欄edit.add(cutItem);edit.add(copyItem);edit.add(pasteItem);edit.add(deleteItem);edit.add(selectAllItem);/格式format=new JMenu("格式 (O)");format.setMnemonic('O');sizeItem=new JMenu("字體大小 ")

36、;colorItem=new JMenu("字體顏色 ");fontItem=new JMenu("字體 ");styleItem=new JMenu("字體風(fēng)格 ");sizes = new JRadioButtonMenuItemsizeNames.length;colors = new JRadioButtonMenuItemcolorNames.length;fonts = new JRadioButtonMenuItemfontNames.length;styles=new JCheckBoxMenuItemstyleNam

37、es.length;styleGroup=new ButtonGroup();fontGroup = new ButtonGroup();colorGroup = new ButtonGroup();13sizeGroup = new ButtonGroup();/ 將每種元素放進(jìn)菜單項(xiàng)和按鈕組中for (int i=0;i<sizes.length;i+)sizesi=new JRadioButtonMenuItem(sizeNamesi);sizesi.addItemListener(new FormatListener();sizeGroup.add(sizesi);sizeIte

38、m.add(sizesi);for (int i=0;i<colors.length;i+)colorsi=new JRadioButtonMenuItem(colorNamesi);colorsi.addItemListener(new FormatListener();colorGroup.add(colorsi);colorItem.add(colorsi);for (int i=0;i<fonts.length;i+)fontsi=new JRadioButtonMenuItem(fontNamesi);fontsi.addItemListener(new FormatLi

39、stener();fontGroup.add(fontsi);fontItem.add(fontsi);for(int i=0;i<styles.length;i+)stylesi=new JCheckBoxMenuItem(styleNamesi);stylesi.addItemListener(new FormatListener();styleItem.add(stylesi);format.add(sizeItem);format.add(colorItem);format.add(fontItem);format.add(styleItem);/ 查看view=new JMen

40、u("關(guān)于我們 (us)");14view.setMnemonic('U');formItem=new JMenuItem("組成成員 ");formItem.addActionListener(new ViewListener();impressionItem=new JMenuItem("學(xué)習(xí)感言 ");impressionItem.addActionListener(new ViewListener();view.add(formItem);view.add(impressionItem);/ 將菜單添加到菜單欄

41、中menuBar.add(files);menuBar.add(edit);menuBar.add(format);menuBar.add(view);/彈出式菜單及其菜單項(xiàng)popup=new JPopupMenu();cutItemPop=new JMenuItem("剪切 (T)");cutItemPop.addActionListener(new EditListener();copyItemPop=new JMenuItem("復(fù)制 (C)");copyItemPop.addActionListener(new EditListener();pa

42、steItemPop=new JMenuItem("粘貼 (P)");pasteItemPop.addActionListener(new EditListener();deleteItemPop=new JMenuItem("刪除 (L)");deleteItemPop.addActionListener(new EditListener();selectAllItemPop=new JMenuItem("全選 (A)");selectAllItemPop.addActionListener(new EditListener();/

43、 添加popup.add(cutItemPop);popup.add(copyItemPop);popup.add(pasteItemPop);popup.add(deleteItemPop);popup.add(selectAllItemPop);/ 實(shí)現(xiàn)彈出式菜單的彈出觸發(fā)器t1.addMouseListener(new MouseAdapter()/ 釋放按鈕觸發(fā)事件public void mouseReleased(MouseEvent e)if(e.isPopupTrigger()/ 指定彈出式菜單的成員以及顯示位置15popup.show(e.getComponent(),e.ge

44、tX(),e.getY(););private class FileListener implements ActionListenerpublic void actionPerformed(ActionEvent e)/"新建 "if(e.getSource()=newItem)t1.setText("");file=null;/"打開(kāi) "if(e.getSource()=openItem)if(file !=null)filechooser.setSelectedFile(file);int m=filechooser.showO

45、penDialog(TextFrame.this);if( m=JFileChooser.APPROVE_OPTION)file=filechooser.getSelectedFile();openFile();/"保存 "if(e.getSource()=saveItem)d=t1.getText();if(file!=null) filechooser.setSelectedFile(file);/ 顯示保存對(duì)話框int m=filechooser.showSaveDialog(TextFrame.this);if(m=JFileChooser.APPROVE_OPTI

46、ON)file=filechooser.getSelectedFile();saveFile();16/"退出 "if(e.getSource()=exitItem)k=t1.getText();/ 如果文本為空或已保存,直接退出,否則保存后退出if(k.equals("") System.exit(0);else if(k.equals(d) System.exit(0);elseTextFrame f=new TextFrame();/新建確認(rèn)型對(duì)話框int n=JOptionPane.showConfirmDialog(f,"是否將文件保

47、存到當(dāng)前位置?","退出 ",JOptionPane.YES_NO_CANCEL_OPTION);if(n=JOptionPane.YES_OPTION)/如果選擇“是” ,則保存文件if(file!=null) filechooser.setSelectedFile(file);int m=filechooser.showSaveDialog(TextFrame.this);if(m=JFileChooser.APPROVE_OPTION)file=filechooser.getSelectedFile();saveFile();if(n=JOptionPane

48、.NO_OPTION)System.exit(0);void openFile()/打開(kāi)的方法tryFileReader fr=new FileReader(file); /FileReader類(lèi)用于讀取字符流int len=(int)file.length();char buffer=new charlen; /以 file的字符數(shù)開(kāi)辟一段緩沖區(qū)fr.read(buffer,0,len); /將 fr從 file中讀取的字符讀入數(shù)組buffer中的某一部分,17fr.close(); /關(guān)閉該流t1.setText(new String(buffer);catch(Exception e)/

49、拋出異常e.printStackTrace();void saveFile()/保存的方法tryFileWriter fw=new FileWriter(file); /FileWriter類(lèi)用于寫(xiě)入字符流fw.write(t1.getText();/將 t1 里的內(nèi)容寫(xiě)入filefw.close(); /關(guān)閉該流catch(Exception e)e.printStackTrace();private class LogoutAction extends WindowAdapter/實(shí)現(xiàn)點(diǎn)擊窗口退出事件監(jiān)聽(tīng)器public void windowClosing(WindowEvent e)s=

50、t1.getText();if(s.equals("") System.exit(0);else if(s.equals(d) System.exit(0);elseTextFrame f=new TextFrame();/ 新建確認(rèn)型對(duì)話框 int n=JOptionPane.showConfirmDialog(f,"是否將文件保存到當(dāng)前位置?"," 退出 ",JOptionPane.YES_NO_OPTION);if(n=JOptionPane.YES_OPTION)/如果選擇“是” ,則保存文件if(file!=null) fi

51、lechooser.setSelectedFile(file);int m=filechooser.showSaveDialog(TextFrame.this);if(m=JFileChooser.APPROVE_OPTION)file=filechooser.getSelectedFile();saveFile();18if(n=JOptionPane.NO_OPTION)System.exit(0);void saveFile()/保存的方法tryFileWriter fw=new FileWriter(file); /FileWriter類(lèi)用于寫(xiě)入字符流fw.write(t1.getTe

52、xt();/將 t1 里的內(nèi)容寫(xiě)入filefw.close(); /關(guān)閉該流catch(Exception e)e.printStackTrace();private class EditListener implements ActionListenerpublic void actionPerformed(ActionEvent e)/ 剪切if(e.getSource()=cutItem|e.getSource()=cutItemPop)t1.cut();/ 復(fù)制if(e.getSource()=copyItem|e.getSource()=copyItemPop)t1.copy();/ 粘貼if(e.getSource()=pasteItem|e.getSource()=pasteItemPop)t1.paste();/ 刪除19if(e.getSource()=deleteItem|e.getSource()=deleteItemPop)text=t1.getText();selected=t1.getSelectedText();int id=text.indexOf(selected);int s

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 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ì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論