资源简介
JAVA实现记事本,课程大作业,记事本功能齐全,和Windows一样
代码片段和文件信息
/**
*
*/
package NotePad;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import java.io.*;
import javax.swing.undo.*;
import javax.swing.border.*;
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.event.*;
import java.awt.datatransfer.*;
/**
* @author Gene
*
*/
public class Notepad extends Jframe implements ActionListenerDocumentListener
{ //菜单
JMenu fileMenueditMenuformatMenuviewMenuhelpMenu;
//右键弹出菜单项
JPopupMenu popupMenu;
JMenuItem popupMenu_UndopopupMenu_CutpopupMenu_CopypopupMenu_PastepopupMenu_DeletepopupMenu_SelectAll;
//“文件”的菜单项
JMenuItem fileMenu_NewfileMenu_OpenfileMenu_SavefileMenu_SaveAsfileMenu_PageSetUpfileMenu_PrintfileMenu_Exit;
//“编辑”的菜单项
JMenuItem editMenu_UndoeditMenu_CuteditMenu_CopyeditMenu_PasteeditMenu_DeleteeditMenu_FindeditMenu_FindNexteditMenu_ReplaceeditMenu_GoToeditMenu_SelectAlleditMenu_TimeDate;
//“格式”的菜单项
JCheckBoxMenuItem formatMenu_LineWrap;
JMenuItem formatMenu_Font;
//“查看”的菜单项
JCheckBoxMenuItem viewMenu_Status;
//“帮助”的菜单项
JMenuItem helpMenu_HelpTopicshelpMenu_AboutNotepad;
//“文本”编辑区域
JTextArea editArea;
//状态栏标签
JLabel statusLabel;
//系统剪贴板
Toolkit toolkit=Toolkit.getDefaultToolkit();
Clipboard clipBoard=toolkit.getSystemClipboard();
//撤销操作
protected UndoManager undo=new UndoManager();
protected UndoableEditListener undoHandler=new UndoHandler();
//其他变量
String oldValue;//存放编辑区原来的内容,用于比较文本是否有改动
boolean isNewFile=true;//是否新文件(未保存过的)
File currentFile;//当前文件名
//构造函数开始
public Notepad()
{
super(“Java记事本“);
//改变系统默认字体
Font font = new Font(“Dialog“ Font.PLAIN 12);
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
object key = keys.nextElement();
object value = UIManager.get(key);
if (value instanceof javax.swing.plaf.FontUIResource) {
UIManager.put(key font);
}
}
//创建菜单条
JMenuBar menuBar=new JMenuBar();
//创建文件菜单及菜单项并注册事件监听
fileMenu=new JMenu(“文件(F)“);
fileMenu.setMnemonic(‘F‘);//设置快捷键ALT+F
fileMenu_New=new JMenuItem(“新建(N)“);
fileMenu_New.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_NInputEvent.CTRL_MASK));
fileMenu_New.addActionListener(this);
fileMenu_Open=new JMenuItem(“打开(O)...“);
fileMenu_Open.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_OInputEvent.CTRL_MASK));
fileMenu_Open.addActionListener(this);
fileMenu_Save=new JMenuItem(“保存(S)“);
fileMenu_Save.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SInputEvent.CTRL_MASK));
fileMenu_Save.addActionListene
- 上一篇:Redis所需要得所有jar包
- 下一篇:气象云图数据解析代码之Java实现
评论
共有 条评论