簡(jiǎn)單記事本的java程序代碼_第1頁(yè)
簡(jiǎn)單記事本的java程序代碼_第2頁(yè)
簡(jiǎn)單記事本的java程序代碼_第3頁(yè)
簡(jiǎn)單記事本的java程序代碼_第4頁(yè)
簡(jiǎn)單記事本的java程序代碼_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡(jiǎn)介

1、簡(jiǎn)單記事本的java程序代碼涉及到兩個(gè)文件:第一個(gè)文件中的代碼:package MyProject;import java.awt.BorderLayout;import javax.swing.JPanel;import javax.swing.JFrame;import java.awt.Dimension;import javax.swing.JMenuBar;import javax.swing.JMenu;import javax.swing.JMenuItem;import javax.swing.JLabel;import java.awt.Rectangle;import ja

2、vax.swing.JTextArea;import javax.swing.JScrollPane;import java.awt.datatransfer.*;import java.io.*;public class MainFrame extends JFrame private static final long serialVersionUID = 1L; private JPanel jContentPane = null; private JMenuBar jJMenuBar = null; private JMenu jMenu = null; private JMenu j

3、Menu1 = null; private JMenu jMenu2 = null; private JMenuItem jMenuItem = null; private JMenuItem jMenuItem1 = null; private JMenuItem jMenuItem2 = null; private JMenuItem jMenuItem3 = null; private JLabel jLabel = null; private JScrollPane jScrollPane = null; private JTextArea jTextArea = null; priv

4、ate JMenuItem jMenuItem4 = null; private JMenuItem jMenuItem5 = null; private JMenuItem jMenuItem6 = null; private JMenuItem jMenuItem7 = null; private static MainFrame myMainFrame=null; private static String textstr=""/用于記錄文本文件的路徑 private File myFile=null; private FileReader myrder=null;

5、private FileWriter mywr=nulJava培訓(xùn)l; /* * This is the default constructor */ public MainFrame() super(); initialize(); /* * This method initializes this * * return void */ private void initialize() this.setSize(412, 350); this.setJMenuBar(getJJMenuBar(); this.setContentPane(getJContentPane(); this.se

6、tTitle("JFrame"); this.addWindowListener(new java.awt.event.WindowAdapter() public void windowActivated(java.awt.event.WindowEvent e) if(!textstr.equals("") try myFile=new File(textstr); if(!myFile.exists() myFile.createNewFile(); myrder=new FileReader(myFile); char mychar=new ch

7、ar(int)myFile.length(); myrder.read(mychar); String tmp=new String(mychar); jTextArea.setText(tmp); myrder.close(); catch(Exception ee) ee.printStackTrace(); public void windowClosing(java.awt.event.WindowEvent e) System.exit(0); ); this.setVisible(true); myMainFrame=this; /* * This method initializ

8、es jContentPane * */ private JPanel getJContentPane() if (jContentPane = null) jLabel = new JLabel(); jLabel.setBounds(new Rectangle(15, 18, 65, 18); jLabel.setText("文件內(nèi)容:"); jContentPane = new JPanel(); jContentPane.setLayout(null); jContentPane.add(jLabel, null); jContentPane.add(getJScr

9、ollPane(), null); return jContentPane; /* * This method initializes jJMenuBar * * return javax.swing.JMenuBar */ private JMenuBar getJJMenuBar() if (jJMenuBar = null) jJMenuBar = new JMenuBar(); jJMenuBar.add(getJMenu(); jJMenuBar.add(getJMenu1(); jJMenuBar.add(getJMenu2(); return jJMenuBar; /* * Th

10、is method initializes jMenu * * return javax.swing.JMenu */ private JMenu getJMenu() if (jMenu = null) jMenu = new JMenu(); jMenu.setText("文件"); jMenu.add(getJMenuItem(); jMenu.add(getJMenuItem1(); jMenu.add(getJMenuItem2(); jMenu.add(getJMenuItem3(); return jMenu; /* * This method initial

11、izes jMenu1 * * return javax.swing.JMenu */ private JMenu getJMenu1() if (jMenu1 = null) jMenu1 = new JMenu(); jMenu1.setText("編輯"); jMenu1.add(getJMenuItem4(); jMenu1.add(getJMenuItem5(); jMenu1.add(getJMenuItem6(); return jMenu1; /* * This method initializes jMenu2 * * return javax.swing

12、.JMenu */ private JMenu getJMenu2() if (jMenu2 = null) jMenu2 = new JMenu(); jMenu2.setText("幫助"); jMenu2.add(getJMenuItem7(); return jMenu2; /* * This method initializes jMenuItem * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem() if (jMenuItem = null) jMenuItem = new JM

13、enuItem(); jMenuItem.setText("打開"); jMenuItem.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) MainFrame.this.myMainFrame.setEnabled(false); SelectTextFile mysl=new SelectTextFile(); mysl.setVisible(true); ); return jMenuItem;

14、/* * This method initializes jMenuItem1 * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem1() if (jMenuItem1 = null) jMenuItem1 = new JMenuItem(); jMenuItem1.setText("關(guān)閉"); jMenuItem1.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt

15、.event.ActionEvent e) try myFile=null; catch(Exception ee) ee.printStackTrace(); jTextArea.setText(""); ); return jMenuItem1; /* * This method initializes jMenuItem2 * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem2() if (jMenuItem2 = null) jMenuItem2 = new JMenuItem(); j

16、MenuItem2.setText("保存"); jMenuItem2.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) try String tmp=jTextArea.getText(); char mychar=tmp.toCharArray(); myFile.delete(); myFile.createNewFile(); mywr=new FileWriter(myFile); mywr.

17、write(mychar); mywr.close(); catch(Exception ee) ee.printStackTrace(); ); return jMenuItem2; /* * This method initializes jMenuItem3 * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem3() if (jMenuItem3 = null) jMenuItem3 = new JMenuItem(); jMenuItem3.setText("退出"); jMenuIte

18、m3.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) System.exit(0); ); return jMenuItem3; /* * This method initializes jScrollPane * * return javax.swing.JScrollPane */ private JScrollPane getJScrollPane() if (jScrollPane = null) jScroll

19、Pane = new JScrollPane(); jScrollPane.setBounds(new Rectangle(15, 46, 371, 225); jScrollPane.setViewportView(getJTextArea(); return jScrollPane; /* * This method initializes jTextArea * * return javax.swing.JTextArea */ private JTextArea getJTextArea() if (jTextArea = null) jTextArea = new JTextArea

20、(); return jTextArea; /* * This method initializes jMenuItem4 * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem4() if (jMenuItem4 = null) jMenuItem4 = new JMenuItem(); jMenuItem4.setText("復(fù)制"); jMenuItem4.addActionListener(new java.awt.event.ActionListener() public void ac

21、tionPerformed(java.awt.event.ActionEvent e) MainFrame.this.setClipboardText(MainFrame.this.getToolkit().getSystemClipboard(),jTextArea.getSelectedText(); ); return jMenuItem4; /* * This method initializes jMenuItem5 * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem5() if (jMenuItem5

22、 = null) jMenuItem5 = new JMenuItem(); jMenuItem5.setText("剪切"); jMenuItem5.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) MainFrame.this.setClipboardText(MainFrame.this.getToolkit().getSystemClipboard(),jTextArea.getSelected

23、Text(); jTextArea.setText(jTextArea.getText().substring(0,jTextArea.getSelectionStart(); ); return jMenuItem5; /* * This method initializes jMenuItem6 * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem6() if (jMenuItem6 = null) jMenuItem6 = new JMenuItem(); jMenuItem6.setText("黏

24、貼"); jMenuItem6.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) try jTextArea.setText(jTextArea.getText().substring(0,jTextArea.getSelectionStart(); jTextArea.setText(jTextArea.getText()+(MainFrame.this.getClipboardText(MainFrame.t

25、his.getToolkit().getSystemClipboard(); catch(Exception ee) ee.printStackTrace(); ); return jMenuItem6; /* * This method initializes jMenuItem7 * * return javax.swing.JMenuItem */ private JMenuItem getJMenuItem7() if (jMenuItem7 = null) jMenuItem7 = new JMenuItem(); jMenuItem7.setText("關(guān)于記事本"); jMenuItem7.addActionListener(new java.awt.event.ActionListener() public void actionPerformed(java.awt.event.ActionEvent e) /暫無代碼! ); return jMenuItem7; public static void main(String args) new Mai

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝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ù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 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)論