Java語(yǔ)言程序設(shè)計(jì)報(bào)告液體混料罐的PLC控制_第1頁(yè)
Java語(yǔ)言程序設(shè)計(jì)報(bào)告液體混料罐的PLC控制_第2頁(yè)
Java語(yǔ)言程序設(shè)計(jì)報(bào)告液體混料罐的PLC控制_第3頁(yè)
Java語(yǔ)言程序設(shè)計(jì)報(bào)告液體混料罐的PLC控制_第4頁(yè)
Java語(yǔ)言程序設(shè)計(jì)報(bào)告液體混料罐的PLC控制_第5頁(yè)
已閱讀5頁(yè),還剩17頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、 Java程序設(shè)計(jì)課程設(shè)計(jì) 題 目 巢湖學(xué)院計(jì)算機(jī)與信息工程學(xué)院實(shí)驗(yàn)報(bào)告記事本程序 院(系) 計(jì)算機(jī)與信息工程學(xué)院 專 業(yè) 軟件工程 學(xué)生姓名 楊 旋 顧瑩瑩 楊燦芳 學(xué) 號(hào) 指導(dǎo)教師 許榮泉 職稱 講 師 論文字?jǐn)?shù) 15875 完成日期: 2015年 1月 3 日目 錄第1章 緒論21.1 開(kāi)發(fā)工具和開(kāi)發(fā)環(huán)境21.1.1 Eclipse21.1.2 JDK(Java Development Kit)21.2 設(shè)計(jì)背景.2第2章 設(shè)計(jì)與分析22.1 需求分析22.2 功能模塊劃分32.2.1 菜單欄32.2.2 文本輸入?yún)^(qū)32.2.3 狀態(tài)欄32.2.4 右鍵菜單32.3 功能模塊流程圖3第3

2、章 記事本程序設(shè)計(jì)33.1 概要設(shè)計(jì)43.1.1 界面設(shè)計(jì)43.1.2 功能設(shè)計(jì)43.1.3 代碼設(shè)計(jì)43.2 詳細(xì)代碼4第4章 程序測(cè)試94.1 打開(kāi)程序94.2 點(diǎn)擊菜單94.3 輸入文字104.4 點(diǎn)擊子菜單10第5章 附錄115.1 心得體會(huì)115.2 參考文獻(xiàn)115.2 源碼11第1章 緒論1.1 開(kāi)發(fā)工具和開(kāi)發(fā)環(huán)境1.1.1 EclipseEclipse是一個(gè)開(kāi)放源代碼的、基于Java的可擴(kuò)展開(kāi)發(fā)平臺(tái)。就其本身而言,它只是一個(gè)框架和一組服務(wù),用于通過(guò)插件組件構(gòu)建開(kāi)發(fā)環(huán)境。利用它我們可以在數(shù)據(jù)庫(kù)和JavaEE的開(kāi)發(fā)、發(fā)布以及應(yīng)用程序服務(wù)器的整合方面極大的提高工作效率。它是功能豐富的J

3、avaEE集成開(kāi)發(fā)環(huán)境,包括了完備的編碼、調(diào)試、測(cè)試和發(fā)布功能,完整支持HTML,Strut,JSP,CSS,Javascript,SQL,Hibernate3。1.1.2 JDK(Java Development Kit)JDK(Java Development Kit)是Sun Microsystems針對(duì)Java開(kāi)發(fā)員的產(chǎn)品。自從Java推出以來(lái),JDK已經(jīng)成為使用最廣泛的Java SDK。JDK 是整個(gè)Java的核心,包括了Java運(yùn)行環(huán)境,Java工具和Java基礎(chǔ)的類庫(kù)。JDK是學(xué)好Java的第一步。而專門(mén)運(yùn)行在x86平臺(tái)的Jrocket在服務(wù)端運(yùn)行效率也要比Sun JDK好很多。

4、從SUN的JDK5.0開(kāi)始,提供了泛型等非常實(shí)用的功能,其版本也不斷更新,運(yùn)行效率得到了非常大的提高4。1.2設(shè)計(jì)背景“記事本”的功能雖然連“寫(xiě)字板”都比不上,但它還是有它自己的獨(dú)門(mén)絕技的。下面我們就來(lái)看看記事本吧。相對(duì)于微軟的Word來(lái)說(shuō)“記事本”的功能確實(shí)是太單薄了,只有:新建,保存,打印,查找,替換這幾個(gè)功能。但是“記事本”卻擁有一個(gè)Word不可能擁有的優(yōu)點(diǎn):打開(kāi)速度快,文件小。我相信對(duì)于這一點(diǎn)大家一定是深有感觸地,一點(diǎn)就打開(kāi);同樣的文本文件用Word保存和用記事本保存的文件大小就大不相同,所以對(duì)于大小在64KB以下的純文本的保存最好還是采用記事本。 記事本另一項(xiàng)不可取代的功能是:可以保

5、存無(wú)格式文件。你可以把記事本編輯的文件保存為:“.html”,“.java”,“.asp”等等任意格式。這使得“記事本”又找到了一個(gè)新的用途:作為程序語(yǔ)言的編輯器。翻開(kāi)任何一本介紹一門(mén)編程語(yǔ)言的入門(mén)教材,里面都會(huì)建議學(xué)生在記事本中編寫(xiě)源程序。 在此我們利用Java的文件輸入輸入流來(lái)實(shí)現(xiàn)簡(jiǎn)單的記事本小程序。第2章 分析與設(shè)計(jì)2.1需求分析現(xiàn)在網(wǎng)絡(luò)上各種文檔編輯器數(shù)不勝數(shù),有EmEditor,UEStudio,GridinSoftNotepad,Notepad+,win32pad,SkimEdit,UniRed,xint。功能也是應(yīng)有盡有,有能改變字體的,有能改變文字顏色的。但是,這些軟件又存在各

6、種各樣的瑕疵或問(wèn)題:有的文件體積相對(duì)于一般文字編輯來(lái)說(shuō)太大;有的功能太繁雜,使初級(jí)使用者一時(shí)難以掌握。僅從日常應(yīng)用方面來(lái)說(shuō),一個(gè)文本編輯器只需一些簡(jiǎn)單實(shí)用的功能就夠了。本程序設(shè)計(jì)就是依照這樣一種使用需要設(shè)計(jì)了一個(gè)簡(jiǎn)單的記事本程序。2.2功能模塊分析2.2.1菜單欄(1) 菜單中有“文件”,“編輯”,“設(shè)置”,“關(guān)于”四個(gè)主菜單。(2) “文件”有“打開(kāi)”“保存”“退出”三個(gè)子菜單:分別用于打開(kāi)文件,保存文件,退出記事本。(3) “編輯”中有“撤銷”,“恢復(fù)”,“剪切”“復(fù)制”“粘貼”“剪貼”,“刪除”六個(gè)子菜單:用于剪切文字,復(fù)制文字,粘貼文字等一系列操作。(4) “設(shè)置”中有“自動(dòng)換行”,“

7、字體顏色”,“恢復(fù)設(shè)置”三個(gè)子菜單,分別用于設(shè)置是否自動(dòng)換行,字體顏色等。(5) “關(guān)于”菜單中有關(guān)于記事本程序的制作日期,作者等信息2.2.2文本輸入?yún)^(qū)用到了“JTextArea”,給用戶輸入文字2.2.3狀態(tài)欄此欄主要功能是顯示出字符總長(zhǎng)、總行數(shù)、當(dāng)前行、當(dāng)前列。2.2.4右鍵菜單此部分為用戶設(shè)計(jì)右鍵操作,方便用戶進(jìn)行一系列的編輯操作,增強(qiáng)本記事本的用戶體驗(yàn)性能。 2.3功能模塊流程圖第3章 記事本程序設(shè)計(jì)3.1概要設(shè)計(jì)設(shè)計(jì)兩個(gè)類,一個(gè)Notepad類繼承JFrame類,然后在Notepad類中添加文件打開(kāi),新建,保存等方法,就可以直接在編譯器中運(yùn)行程序。2.1.1:界面設(shè)計(jì)在主界面中設(shè)計(jì)

8、一個(gè)新建對(duì)象Notepad,由Notepad繼續(xù)自JFrame,故得到Notepad容器,并在其中加入一個(gè)下拉菜單和一個(gè)文本域控件,把該容器設(shè)置為GridLayout(2,1)布局。3.1.2:功能設(shè)計(jì)在下拉菜單中加入子菜單并進(jìn)行監(jiān)聽(tīng),分別實(shí)現(xiàn)對(duì)文件的操作功能。點(diǎn)擊不同菜單項(xiàng)時(shí),顯示不同界面。3.1.3:代碼設(shè)計(jì)編寫(xiě)每個(gè)控件的相關(guān)代碼,并進(jìn)行調(diào)試。3.2詳細(xì)代碼3.2.1:界面設(shè)計(jì)創(chuàng)建一個(gè)下拉菜單和文本域,在文本域中顯示編輯的文件信息。JMenu fileMenu=new JMenu(文件(F) ;JMenuItem newItem=new JMenuItem(新建);JMenuItem op

9、enItem=new JMenuItem(打開(kāi).);JMenuItem saveItem=new JMenuItem(另存為.);JMenuItem copyItem=new JMenuItem(復(fù)制);JMenuItem tieItem=new JMenuItem(粘貼);JMenuItem aboutItem=new JMenuItem(關(guān)于程序);JMenuItem exitItem= new JMenuItem(退出);JMenu formatMenu=new JMenu(設(shè)置(S);String colors=黑色,藍(lán)色,紅色,綠色,粉色,桔黃色;JMenu colorMenu=ne

10、w JMenu(顏色);JMenu sizeMenu=new JMenu(大小);String size=10,16,24,36;String fontNames=幼圓,微軟雅黑,隸書(shū),楷體_GB2312,華文新魏;JMenu fontMenu=new JMenu(字體);String styleNames=加黑,斜體;JMenu FindMenu = new JMenu(查找(T);FindMenu.setMnemonic(T);JMenuItem searchMenu = new JMenuItem(查找);JMenuItem replaceMenu = new JMenuItem(替換)

11、;JMenu lookMenu=new JMenu(查看(L);/設(shè)置菜單項(xiàng)JMenuItem taiItem=new JMenuItem(狀態(tài)欄);JMenu helpMenu=new JMenu(幫助(H); /設(shè)置菜單項(xiàng)JMenuItem helpItem=new JMenuItem(幫助主題);helpMenu.add(helpItem);helpMenu.addSeparator();/設(shè)置分割線JMenuItem about1Item=new JMenuItem(關(guān)于記事本.);界面如下:3.2.2功能設(shè)計(jì) 打開(kāi)窗口事件OpenHander:class OpenHandler im

12、plements ActionListener public void actionPerformed(ActionEvent e)JFileChooser jc=new JFileChooser();int rVal=jc.showOpenDialog(C3.this);/顯示打開(kāi)文件的對(duì)話框if(rVal=JFileChooser.APPROVE_OPTION)File dir=jc.getCurrentDirectory();File file=jc.getSelectedFile();filenameTf.setText(file.getName();dirTf.setText(dir

13、.toString();/在文本域內(nèi)顯示文本文件內(nèi)容contentTa.setText(read(new File(dir,file.getName();if(rVal=JFileChooser.CANCEL_OPTION) filenameTf.setText(你取消了當(dāng)前選擇!);dirTf.setText( ); 打開(kāi)時(shí)讀取文字事件:private String read(File file)/打開(kāi)時(shí)的讀取tryBufferedReader reader=new BufferedReader(new InputStreamReader(new FileInputStream(file),

14、GBK);String data=null;StringBuffer buffer=new StringBuffer();while(data=reader.readLine()!=null)buffer.append(data+n);reader.close();return buffer.toString();catch(IOException e)throw new RuntimeException(e); 保存事件SaveHandler:class SaveHandler implements ActionListener /保存public void actionPerformed(

15、ActionEvent e)JFileChooser jc=new JFileChooser();int rVal=jc.showSaveDialog(C3.this);/顯示保存文件的對(duì)話框if(rVal=JFileChooser.APPROVE_OPTION)File dir=jc.getCurrentDirectory();File file=jc.getSelectedFile();filenameTf.setText(file.getName();dirTf.setText(dir.toString();write(new File(dir,file.getName(),conten

16、tTa.getText();if(rVal=JFileChooser.CANCEL_OPTION)filenameTf.setText(你取消了當(dāng)前選擇!);dirTf.setText( ); 粘貼文件: tieItem.addActionListener(new ActionListener() /響應(yīng)粘貼事件public void actionPerformed(ActionEvent event)contentTa.setText(contentTa.getText()+str);); 查找替換功能: public void showFind() setTitle(查找); setSiz

17、e(280,60); setVisible(true); public void showReplace() setTitle(查找替換); setSize(280,110); setVisible(true); private void find() String text=ta.getText(); String str=tFind.getText(); int end=text.length(); int len=str.length(); int start=ta.getSelectionEnd(); if(start=end) start=0; for(;start=end-len;

18、start+) if(text.substring(start,start+len).equals(str) ta.setSelectionStart(start); ta.setSelectionEnd(start+len); return; /若找不到待查字符串,則將光標(biāo)置于末尾 ta.setSelectionStart(end); ta.setSelectionEnd(end); public Button getBFind() return bFind; private void replace() String str=tReplace.getText(); if(ta.getSel

19、ectedText().equals(tFind.getText() ta.replaceRange(str,ta.getSelectionStart(),ta.getSelectionEnd(); else find();第4章 程序測(cè)試4.1打開(kāi)程序4.2點(diǎn)擊菜單4.3輸入文字4.4點(diǎn)擊子菜單第5章 附錄5.1心得體會(huì)此次課程設(shè)計(jì)有我們寢室一起共同合作完成,花費(fèi)的時(shí)間整整兩天。在這期 間我們共同協(xié)作,互幫互助取得了很好的效率,也為我們構(gòu)建和諧寢室,學(xué)習(xí)氣氛良好寢室做出了一定的貢獻(xiàn)。在這期間我領(lǐng)略到了團(tuán)隊(duì)協(xié)作的重要性,也看到了團(tuán)隊(duì)合作的高效率性。還有通過(guò)這次試驗(yàn)我學(xué)習(xí)到了其他室友的一些學(xué)習(xí)方

20、法,比如追查API,如何在短時(shí)間內(nèi)學(xué)習(xí)一個(gè)自己不懂的東西那就是利用好所有的搜索引擎??傊舜握n程設(shè)計(jì)不僅在知識(shí)少我是長(zhǎng)了見(jiàn)識(shí),在生活上我也長(zhǎng)了見(jiàn)識(shí)。5.2參考文獻(xiàn)a.黃曉東等編著Java課程設(shè)計(jì)案例精編(第二版)M.北京:中國(guó)水利水電出版社,2007b.李興華等編著Java開(kāi)發(fā)實(shí)戰(zhàn)經(jīng)典Java開(kāi)發(fā)實(shí)戰(zhàn)經(jīng)典北京:清華大學(xué)出版社,2009c.李尊朝蘇軍Java程序設(shè)計(jì)(第二版)圖形用戶界面設(shè)計(jì)、Swing組件中國(guó)鐵道出版社,20075.3源碼package p1;import javax.swing.*;import java.awt.*;import java.awt.event.*;impor

21、t java.io.*;public class Notepad extends JFrame /* * 記事本程序 */private static final long serialVersionUID = 1L;/定義菜單項(xiàng)private final Color colorValues=Color.BLACK,Color.BLUE,Color.RED,Color.GREEN,Color.PINK,Color.ORANGE;private JRadioButtonMenuItem colorItems,fonts,sizeItems;private JCheckBoxMenuItem st

22、yleItems;private JLabel displayLabel;private ButtonGroup fontGroup,colorGroup,sizeGroup;/創(chuàng)建按鈕組對(duì)象,實(shí)現(xiàn)JRadioButton多選一功能private int style;/定義字體大小int fonti=10; Font font; /JRadioButton r1,r2,r3; /聲明按鈕對(duì)象 ButtonGroup bg=new ButtonGroup( ); / private String str=new String();/用來(lái)存放用戶當(dāng)前選擇的文本/private JTextField

23、 filenameTf=new JTextField(), dirTf=new JTextField();private JPanel optPane=new JPanel();private JPanel navigetePane=new JPanel();private JTextArea contentTa=new JTextArea(5,20);/public Notepad(String title)super(title);/設(shè)置字體大小/ r1=new JRadioButton(10); /r1.addActionListener(new sizeHandler(); / opt

24、Pane.add(r1); /加載按鈕到界面上 /r2=new JRadioButton(16); /r2.addActionListener(new sizeHandler(); /optPane.add(r2); / r3=new JRadioButton(24); /r3.addActionListener(new sizeHandler(); / optPane.add(r3); / bg.add(r1); /加載按鈕到按鈕組 / bg.add(r2); / bg.add(r3);/dirTf.setEditable(false); / 設(shè)置為不可編輯filenameTf.setEdi

25、table(false); /設(shè)置為不可編輯navigetePane.setLayout(new GridLayout(2,1);navigetePane.add(filenameTf); /添加navigetePane.add(dirTf);Container contentPane=getContentPane();contentPane.add(optPane,BorderLayout.SOUTH);contentPane.add(navigetePane,BorderLayout.NORTH);contentPane.add(new JScrollPane(contentTa),Bor

26、derLayout.CENTER);setSize(500,300);setVisible(true);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /設(shè)置響應(yīng)關(guān)閉按鈕JMenu fileMenu=new JMenu(文件(F) ;fileMenu.setMnemonic(F);/設(shè)置快捷鍵JMenuItem newItem=new JMenuItem(新建);fileMenu.add(newItem); newItem.addActionListener( new ActionListener()/顯示消息對(duì)話框public void act

27、ionPerformed(ActionEvent event) contentTa.setText( ); );/JMenuItem openItem=new JMenuItem(打開(kāi).);fileMenu.add(openItem);openItem.addActionListener(new OpenHandler();JMenuItem saveItem=new JMenuItem(另存為.);fileMenu.add(saveItem);fileMenu.addSeparator();/設(shè)置分割線saveItem.addActionListener(new SaveHandler();

28、JMenuItem copyItem=new JMenuItem(復(fù)制);copyItem.setMnemonic(C);/設(shè)置快捷鍵fileMenu.add(copyItem);copyItem.addActionListener(new ActionListener() /響應(yīng)復(fù)制事件public void actionPerformed(ActionEvent event)str=contentTa.getSelectedText(););/JMenuItem tieItem=new JMenuItem(粘貼);fileMenu.add(tieItem);tieItem.setMnemo

29、nic(V);/設(shè)置快捷鍵fileMenu.addSeparator();/設(shè)置分割線tieItem.addActionListener(new ActionListener() /響應(yīng)粘貼事件public void actionPerformed(ActionEvent event)contentTa.setText(contentTa.getText()+str););/JMenuItem aboutItem=new JMenuItem(關(guān)于程序);fileMenu.add(aboutItem);aboutItem.addActionListener( new ActionListener

30、() /顯示消息對(duì)話框public void actionPerformed(ActionEvent event)JOptionPane.showMessageDialog(Notepad.this,這是(*_*)的記事本,About,JOptionPane.PLAIN_MESSAGE););JMenuItem exitItem= new JMenuItem(退出);fileMenu.add(exitItem);exitItem.addActionListener( /響應(yīng)退出事件new ActionListener()public void actionPerformed(ActionEve

31、nt event) System.exit(0););JMenuBar bar=new JMenuBar();setJMenuBar(bar); /在frame中設(shè)置菜單條bar.add(fileMenu);JMenu formatMenu=new JMenu(設(shè)置(S);formatMenu.setMnemonic(S);String colors=黑色,藍(lán)色,紅色,綠色,粉色,桔黃色;JMenu colorMenu=new JMenu(顏色);JMenu sizeMenu=new JMenu(大小);String size=10,16,24,36;sizeItems=new JRadioB

32、uttonMenuItemsize.length;sizeGroup=new ButtonGroup();/colorItems=new JRadioButtonMenuItemcolors.length;colorGroup=new ButtonGroup();ItemHandler itemHandler=new ItemHandler();for(int count=0;countcolors.length;count+)colorItemscount=new JRadioButtonMenuItem(colorscount);colorMenu.add(colorItemscount)

33、;colorGroup.add(colorItemscount);colorItemscount.addActionListener(itemHandler);colorItems0.setSelected(true);formatMenu.add(colorMenu);formatMenu.addSeparator();/設(shè)置分割線sizeItems=new JRadioButtonMenuItemcolors.length;sizeGroup=new ButtonGroup();for(int count=0;countsize.length;count+)sizeItemscount=n

34、ew JRadioButtonMenuItem(sizecount);sizeMenu.add(sizeItemscount);sizeGroup.add(sizeItemscount);sizeItemscount.addActionListener(itemHandler);formatMenu.add(sizeMenu);sizeItems0.setSelected(true);formatMenu.addSeparator();/設(shè)置分割線String fontNames=幼圓,微軟雅黑,隸書(shū),楷體_GB2312,華文新魏;JMenu fontMenu=new JMenu(字體);fo

35、nts=new JRadioButtonMenuItemfontNames.length;fontGroup=new ButtonGroup();for(int count=0;countfonts.length;count+)fontscount=new JRadioButtonMenuItem(fontNamescount);fontMenu.add(fontscount);fontGroup.add(fontscount);fontscount.addActionListener(itemHandler);fonts0.setSelected(true);fontMenu.addSepa

36、rator();/設(shè)置分割線String styleNames=加黑,斜體;styleItems=new JCheckBoxMenuItemstyleNames.length;StyleHandler styleHandler=new StyleHandler();for(int count=0;countstyleNames.length;count+)styleItemscount=new JCheckBoxMenuItem(styleNamescount);fontMenu.add(styleItemscount);styleItemscount.addItemListener(styl

37、eHandler);formatMenu.add(fontMenu);bar.add(formatMenu);/添加到菜單項(xiàng) JMenu FindMenu = new JMenu(查找(T);FindMenu.setMnemonic(T);JMenuItem searchMenu = new JMenuItem(查找);JMenuItem replaceMenu = new JMenuItem(替換);FindMenu.add(searchMenu);FindMenu.add(replaceMenu);searchMenu.addActionListener( new ActionListen

38、er() /顯示消息對(duì)話框 public void actionPerformed(ActionEvent event)JFrame ss = new JFrame(查找);JLabel tt = new JLabel(查找);JTextField txt = new JTextField();JButton but = new JButton(查找);ss.setLayout(null);ss.setLocation(150,150);Dimension dim = new Dimension();dim.setSize(300, 100);tt.setBounds(10,20, 40, 2

39、0);txt.setBounds(70,20,100,20);but.setBounds(190,20,80,20);but.addActionListener( new ActionListener() /顯示消息對(duì)話框 public void actionPerformed(ActionEvent event)JOptionPane.showMessageDialog(Notepad.this,查找成功了,查找,JOptionPane.PLAIN_MESSAGE););ss.add(but);ss.add(txt);ss.add(tt);ss.setSize(dim);ss.setVisi

40、ble(true););replaceMenu.addActionListener( new ActionListener() /顯示消息對(duì)話框 public void actionPerformed(ActionEvent event)JFrame ss = new JFrame(替換);JLabel tt = new JLabel(替換);JTextField txt = new JTextField();JButton but = new JButton(替換);ss.setLayout(null);ss.setLocation(150,150);Dimension dim = new

41、Dimension();dim.setSize(300, 100);tt.setBounds(10,20, 40, 20);txt.setBounds(70,20,100,20);but.setBounds(190,20,80,20);but.addActionListener( new ActionListener() /顯示消息對(duì)話框 public void actionPerformed(ActionEvent event)JOptionPane.showMessageDialog(Notepad.this,替換成功了,替換,JOptionPane.PLAIN_MESSAGE););ss

42、.add(but);ss.add(txt);ss.add(tt);ss.setSize(dim);ss.setVisible(true););bar.add(FindMenu);JMenu lookMenu=new JMenu(查看(L);/設(shè)置菜單項(xiàng)JMenuItem taiItem=new JMenuItem(狀態(tài)欄);lookMenu.add(taiItem);taiItem.addActionListener( new ActionListener() /顯示消息對(duì)話框 public void actionPerformed(ActionEvent event)JOptionPane.

43、showMessageDialog(Notepad.this,歡迎使用楊旋的記事本程序!,狀態(tài)欄,JOptionPane.PLAIN_MESSAGE););bar.add(lookMenu);JMenu helpMenu=new JMenu(幫助(H); /設(shè)置菜單項(xiàng)JMenuItem helpItem=new JMenuItem(幫助主題);helpMenu.add(helpItem);helpMenu.addSeparator();/設(shè)置分割線JMenuItem about1Item=new JMenuItem(關(guān)于記事本.);helpMenu.add(about1Item);bar.ad

44、d(helpMenu);about1Item.addActionListener( new ActionListener()/顯示消息對(duì)話框public void actionPerformed(ActionEvent event)JOptionPane.showMessageDialog(Notepad.this,36楊旋!,關(guān)于記事本,JOptionPane.PLAIN_MESSAGE););getContentPane().setBackground(Color.WHITE);setSize(700,500);setVisible(true);setDefaultCloseOperati

45、on(JFrame.EXIT_ON_CLOSE);public static void main (String args)new Notepad(楊旋的記事本);class OpenHandler implements ActionListener /打開(kāi)窗口事件public void actionPerformed(ActionEvent e)JFileChooser jc=new JFileChooser();int rVal=jc.showOpenDialog(Notepad.this);/顯示打開(kāi)文件的對(duì)話框if(rVal=JFileChooser.APPROVE_OPTION)Fi

46、le dir=jc.getCurrentDirectory();File file=jc.getSelectedFile();filenameTf.setText(file.getName();dirTf.setText(dir.toString();/在文本域內(nèi)顯示文本文件內(nèi)容contentTa.setText(read(new File(dir,file.getName();if(rVal=JFileChooser.CANCEL_OPTION) filenameTf.setText(你取消了當(dāng)前選擇!);dirTf.setText( );class SaveHandler implements ActionListener /保存public void actionPerformed(ActionEve

溫馨提示

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

評(píng)論

0/150

提交評(píng)論