資源簡介
仿照 Window 系統中的“記事本”利用 Java 的 GUI 和文件輸入輸出流實現一
個簡單的記事本程序。能實現編輯、保存、另存為、查找和替換等功能。

代碼片段和文件信息
package?com.sxt.nodepad.view;
import?java.awt.*;
import?java.awt.datatransfer.*;
import?java.awt.event.*;
import?java.io.*;
import?javax.swing.*;
public?class?NotepadMainframe?extends?Jframe?implements?ActionListener{
????private?static?final?long?serialVersionUID?=?8585210209467333480L; //序列號
????public?Clipboard?clipboard?=?new?Clipboard(“系統剪切板“); //剪貼板
????private?JPanel?contentPane; //容器
????private?JTextArea?textArea; //文本框
????private?JMenu?itemEdititemHelp; //菜單
????private?JScrollPane?scrollPane;?//滾動條
????private?JMenuItem?itemOpenitemSaveitemSaveAsitemNewitemAboutNotepaditemCutitemCopyitemPasteitemFinditemReplaceitemSelectAllitemExit; //菜單條
????String?currentFileName=null; //當前文件名
????public?static?void?main(String[]?args)?{ //啟動應用程序
????????EventQueue.invokeLater(new?Runnable()?{ //不允許同時從該隊列中指派多個事件
????????????public?void?run()?{
????????????????try?{
????????????????????NotepadMainframe?frame?=?new?NotepadMainframe();
????????????????????frame.setVisible(true); //顯示窗口
????????????????????frame.setIconImage(new?ImageIcon(SystemParam.class.getResource(“k.png“)).getImage());
????????????????}catch?(Exception?e)?{e.printStackTrace();}
????????????}
????????});
????}
????public?NotepadMainframe()?{ //創建frame
???? try?{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}? //設置圖形界面外觀
???? catch?(ClassNotFoundException?e1)?{e1.printStackTrace();}?
???? catch?(InstantiationException?e1)?{e1.printStackTrace();}?
???? catch?(IllegalAccessException?e1)?{e1.printStackTrace();}?
???? catch?(UnsupportedLookAndFeelException?e1)?{e1.printStackTrace();}
????????settitle(“記事本“);????
????????setDefaultCloseOperation(DO_NOTHING_ON_CLOSE); //設置用戶在此窗體上發起?“close“?時不執行任何操作
????????setBounds(400?180?600?400); //設置窗口位置和大小
????????JMenuBar?menuBar?=?new?JMenuBar(); //菜單欄
????????setJMenuBar(menuBar);
????????
????????JMenu?itemFile?=?new?JMenu(“文件(F)“);
????????itemFile.setMnemonic(‘F‘); //設置快捷鍵“Alt+F“
????????menuBar.add(itemFile); //將“文件“菜單添加到菜單欄上
????????
????????itemNew?=?new?JMenuItem(“新建(N)“); //創建“新建“菜單條
????????itemNew.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Njava.awt.Event.CTRL_MASK)); //設置“新建“快捷鍵?Ctrl+N
????????itemNew.addActionListener(this); //注冊監聽者
????????itemFile.add(itemNew); //將“新建“菜單條添加到“文件“菜單
????????
????????itemOpen?=?new?JMenuItem(“打開(O)“);
????????itemOpen.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Ojava.awt.Event.CTRL_MASK));
????????itemOpen.addActionListener(this);
????????itemFile.add(itemOpen);
????????
????????itemSave?=?new?JMenuItem(“保存(S)“);
????????itemSave.setAccelerator(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Sjava.awt.Event.CTRL_MASK));???
????????itemSave.addActionListener(this);
????????itemFile.add(itemSave);
????????
????????itemSaveAs?=?new?JMenuItem(“另存為(A)“);
????????itemSaveAs.addActionListener(this);
????????itemFile.add(itemSaveAs);
????????itemFile.addSepa
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????301??2018-05-17?20:55??jishiben\jishiben\.classpath
?????文件????????384??2018-05-17?20:55??jishiben\jishiben\.project
?????文件????????598??2018-05-17?20:55??jishiben\jishiben\.settings\org.eclipse.jdt.core.prefs
?????文件?????233894??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\k.png
?????文件???????1109??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\NotepadMainfr
?????文件???????1003??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\NotepadMainfr
?????文件???????1286??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\NotepadMainfr
?????文件???????3340??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\NotepadMainfr
?????文件???????2537??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\NotepadMainfr
?????文件????????892??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\NotepadMainfr
?????文件??????10938??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\NotepadMainfr
?????文件????????529??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view\SystemParam.class
?????文件?????233894??2018-05-17?20:55??jishiben\jishiben\src\com\sxt\nodepad\view\k.png
?????文件??????17991??2018-05-17?20:55??jishiben\jishiben\src\com\sxt\nodepad\view\NotepadMainfr
?????文件????????157??2018-05-17?20:55??jishiben\jishiben\src\com\sxt\nodepad\view\SystemParam.java
?????文件?????513024??2018-05-17?20:58??java設計性實驗李英源.doc
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad\view
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\src\com\sxt\nodepad\view
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt\nodepad
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\src\com\sxt\nodepad
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\bin\com\sxt
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\src\com\sxt
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\bin\com
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\src\com
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\.settings
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\bin
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben\src
?????目錄??????????0??2018-05-17?20:55??jishiben\jishiben
?????目錄??????????0??2018-05-17?20:56??jishiben
-----------?---------??----------?-----??----
............此處省略2個文件信息
- 上一篇:八數碼問題寬度優先搜索Java實現
- 下一篇:java簡單推箱子小游戲
評論
共有 條評論