package code;
import java.io.*;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
import java.awt.*;
import java.awt.event.*;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.filechooser.FileFilter;
import javax.swing.text.BadLocationException;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.undo.UndoManager;
/**
* 这是一款拓展Windows XP系统自带记事本的程序,该程序除了支持Windows XP记事本的功能外,还提供了多种功能,令记事本不再单调!<br>
* 特色:<br>
* (1)支持windows xp自带记事本的所有功能!<br>
* (2)增强的文本字体功能,可以设置字体颜色以及字体背景颜色等等,并且提供预览,多姿多彩,让你的记事本不再单调!!!<br>
* (3)可以改变文本编辑框的背景颜色,愉悦心情!<br>
* (4)改善xp记事本,支持重做(Redo)功能,更加方便快捷! <br>
* (5)增加工具栏,更加方便快捷!<br>
* (6)增强的替换功能,可选替换方向,适应与所有替换情况!<br>
* (7)状态栏显示功能,带给你最方便快捷的使用提示和实时字数统计,更加容易操作和习惯!<br>
* (8)完善的字数统计功能,让你犹如在WORD上操作!<br>
* (9)完美兼容Windows XP记事本所有快捷键,完全不存在适应问题!<br>
* (10)再也不用担心个人做的记事本无法打印,页面设置和打印没问题!<br>
* (11)使用windows xp友好界面风格,摒弃JAVA程序的界面,更加习惯!<br>
* (12)程序更加精悍!
* <p>
* 任何问题,联系作者:许子彦 QQ:125177027 E-mail:micaroo@vip.qq.com
* <p>
*
* @author 许子彦<br>
* 厦门大学软件学院软件工程系06级<br>
* 学号:24320062204504
*
* @version 2.01
*
*/
public class notepad extends JFrame implements ActionListener, ItemListener,
WindowListener, MouseListener {
Container c = this.getContentPane();
File file = null;// 当前文件
JFileChooser filechooser = new JFileChooser();
String oldValue; // 存放编辑区原来的内容,用于比较文本是否有改动
JMenuBar bar = new JMenuBar();
// 颜色拾取器,设置背景颜色时调用
JColorChooser colorchooser = new JColorChooser();
// 初始化的字体颜色和字体背景颜色,并且存储更改后的颜色设置
Color forecolor = Color.BLACK, backcolor = Color.WHITE;
// 菜单栏
JMenu fileMenu = new JMenu("文件(F)");
JMenu editMenu = new JMenu("编辑(E)");
JMenu formatMenu = new JMenu("格式(O)");
JMenu viewMenu = new JMenu("查看(V)");
JMenu helpMenu = new JMenu("帮助(H)");
// 菜单选项
JMenuItem newItem = new JMenuItem("新建(N)");
JMenuItem openItem = new JMenuItem("打开(O)...");
JMenuItem saveItem = new JMenuItem("保存(S)");
JMenuItem saveasItem = new JMenuItem("另存为...");
JMenuItem uniformItem = new JMenuItem("页面设置(U)...");
JMenuItem printItem = new JMenuItem("打印(P)...");
JMenuItem exitItem = new JMenuItem("退出(X)");
JMenuItem undoItem = new JMenuItem("撤消(U)");
JMenuItem redoItem = new JMenuItem("重做(R)");
JMenuItem cutItem = new JMenuItem("剪切(T)");
JMenuItem copyItem = new JMenuItem("复制(C)");
JMenuItem pasteItem = new JMenuItem("粘贴(P)");
JMenuItem deleteItem = new JMenuItem("删除(L)");
JMenuItem searchItem = new JMenuItem("查找(F)...");
JMenuItem searchnextItem = new JMenuItem("查找下一个(N)...");
JMenuItem replaceItem = new JMenuItem("替换(R)...");
JMenuItem gotoItem = new JMenuItem("转到(G)");
JMenuItem seleteAllItem = new JMenuItem("全选(A)");
JMenuItem dateItem = new JMenuItem("时间/日期(D)");
JMenuItem fontItem = new JMenuItem("字体(E)...");
JMenuItem colorItem = new JMenuItem("颜色(H)...");
JMenuItem countItem = new JMenuItem("字数统计");
JMenuItem aboutItem = new JMenuItem("关于(A)");
// 右键菜单选项
JMenuItem undopopupItem = new JMenuItem("撤消CTRL+Z");
JMenuItem redopopupItem = new JMenuItem("重做CTRL+R");
JMenuItem cutpopupItem = new JMenuItem("剪切CTRL+X");
JMenuItem copypopupItem = new JMenuItem("复制CTRL+C");
JMenuItem pastepopupItem = new JMenuItem("粘贴CTRL+V");
JMenuItem deletepopupItem = new JMenuItem("删除Delete");
JMenuItem seleteAllpopupItem = new JMenuItem("全选CTRL+A");
JMenuItem fontpopupItem = new JMenuItem("字体...CTRL+F");
JMenuItem colorpopupItem = new JMenuItem("颜色...CTRL+I");
// 自动换行使用CheckBox
JCheckBoxMenuItem lineItem = new JCheckBoxMenuItem("自动换行(W)");
JCheckBoxMenuItem statueItem = new JCheckBoxMenuItem("状态栏");
// 工具栏图标
Icon newicon, openicon, saveicon, undoicon, redoicon, copyicon, pasteicon,
cuticon, deleteicon, fonticon, coloricon, helpicon;
// 工具栏的图标button
JButton newButton, openButton, saveButton, undoButton, redoButton,
copyButton, pasteButton, cutButton, deleteButton, fontButton,
colorButton, helpButton, fontcolorchooser, fontbackcolorchooser;
// 显示字体效果预览用的JLabel
JLabel fontPreviewLabel = new JLabel("预览");
// 记事本框
JTextPane text = new JTextPane();
// 撤销管理器,使用在撤销和重做功能
UndoManager undo;
// 记事本框滚动条
JScrollPane scroller = new JScrollPane(text);
// 字体设置所使用的ComboBox,分别是字体名称、字号大小、文字样式、文字颜色、文字背景颜色
private JList fontName = null, fontSize = null, fontStyle = null;
// 改变文字样式所使用的文本形式
private StyledDocument doc = null;
// 继承ActionListener的内部类对象
ActionHandler handler = new ActionHandler();
// 用于标志是否是新的文件
boolean newfileFlag = true;
// 调用打印机所需
PrinterJob prtMe = PrinterJob.getPrinterJob();
// 有右键,才方便
JPopupMenu popupMenu;
// 状态栏
JLabel statuelabel = new JLabel("状态栏");
public notepad() {
super("新建 文本文档");
//设置显示位置
Toolkit kt=this.getToolkit();
this.setLocation(kt.getScreenSize().width/2-180, kt.getScreenSize().height/2-180);
// 以假乱真呵呵,把JFrame左边的JAVA图标改成记事本的图标,这下更像是记事本了
setIconImage(Toolkit.getDefaultToolkit().createImage("image/标题.gif"));
// 获得JTextPane的Document
Font defaultFont = new Font("宋体", Font.PLAIN, 14);// 默认字体
text.setFont(defaultFont);
doc = text.getStyledDocument();
// 窗口事件监听器,点击关闭时使用
this.addWindowListener(this);
// 设置布局
c.setLayout(new BorderLayout());
// 设置菜单
setJMenuBar(bar);
// 撤销重做管理器,添加监听器
undo = new UndoManager();
text.getDocument().addUndoableEditListener(undo);
// 添加组件
bar.add(fileMenu);
fileMenu.setMnemonic('f');
fileMenu.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
statuelabel.setText("文件菜单(ALT+F)");
}
});
bar.add(editMenu);
editMenu.setMnemonic('e');
editMenu.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
statuelabel.setText("编辑菜单(ALT+E)");
}
});
bar.add(formatMenu);
formatMenu.setMnemonic('o');
formatMenu.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
statuelabel.setText("格式菜单(ALT+O)");
}
});
bar.add(viewMenu);
viewMenu.setMnemonic('v');
viewMenu.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
statuelabel.setText("查看菜单(ALT+V)");
}
});
bar.add(helpMenu);
helpMenu.setMnemonic('h');
helpMenu.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
statuelabel.setText("帮助菜单(ALT+H)");
}
});
// 文件菜单组件
fileMenu.add(newItem);
newItem.setMnemonic('n');
newItem.setAccelerator(KeyStroke.getKeyStroke('N', Event.CTRL_MASK,
false));
newItem.addMouseListener(new MouseAdapter() {
public void mouseEntered(MouseEvent e) {
statuelabel.setText("新建(CTRL+N)");
}
});
newItem.addActionListener(this);
fileMenu.add(openItem);
openItem.setMnemonic('o');
openItem.setAccelerator(KeyStroke.ge
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
NotePad2.0.rar (92个子文件)
NotePad2.0
.classpath 226B
code
notepad$49.class 727B
notepad$41.class 723B
notepad$36.class 727B
notepad$50.class 727B
notepad$16.class 727B
notepad$38.class 727B
notepad$14.class 727B
notepad$7.class 725B
notepad$28.class 718B
notepad$11.class 727B
notepad$31.class 727B
notepad$21.class 727B
notepad$56.class 2KB
notepad$42.class 727B
notepad$45.class 727B
notepad$12.class 715B
notepad$34.class 727B
notepad$FontAttrib.class 3KB
notepad$57.class 717B
notepad$43.class 727B
notepad$55.class 1KB
notepad$19.class 727B
notepad$33.class 727B
notepad$32.class 727B
notepad$3.class 730B
notepad$67.class 1KB
notepad$22.class 727B
notepad$68.class 1KB
notepad$47.class 727B
notepad$2.class 730B
notepad$64.class 760B
notepad$46.class 727B
notepad$39.class 727B
notepad$24.class 730B
notepad$ActionHandler.class 2KB
notepad$61.class 2KB
notepad.class 21KB
JAVAFileFilter.class 1KB
notepad$40.class 727B
notepad$44.class 727B
notepad$17.class 727B
notepad$63.class 759B
notepad$53.class 718B
notepad$18.class 727B
notepad$51.class 1KB
notepad$20.class 732B
notepad$58.class 2KB
notepad$1.class 730B
notepad$13.class 727B
notepad$65.class 1KB
notepad$6.class 725B
notepad$60.class 2KB
notepad$10.class 721B
notepad$69.class 1KB
notepad$35.class 727B
notepad$9.class 716B
notepad$48.class 727B
notepad.java 62KB
notepad$29.class 723B
notepad$54.class 817B
notepad$8.class 725B
notepad$37.class 727B
notepad$62.class 3KB
notepad$52.class 718B
notepad$4.class 730B
notepad$66.class 1KB
notepad$59.class 757B
notepad$5.class 730B
notepad$30.class 727B
notepad$15.class 727B
notepad$27.class 721B
notepad$25.class 727B
notepad$23.class 727B
notepad$26.class 727B
.project 386B
image
help.gif 239B
about.gif 30KB
undo.gif 92B
color.GIF 615B
标题.gif 999B
new.GIF 377B
paste.gif 137B
redo.gif 92B
open.GIF 234B
delete.gif 76B
cut.gif 91B
close.gif 101B
copy.gif 104B
winter.jpg 14KB
font.GIF 601B
save.gif 122B
共 92 条
- 1
资源评论
- dd11070602702012-06-27功能完善,不过程序的图片无法正常执行
micaroo
- 粉丝: 9
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功