java GUI实现记事本窗口

本文介绍了使用纯Java实现记事本窗口的过程,包括Accelerator类用于添加快捷键,Mnemonic类用于设置热键,以及Text类的设计。文章提到了程序的一些改进点,如减少Mnemonic类中menuItems数组的长度和优化Text类的方法。尽管功能已基本实现,但作者指出,真正的程序设计不仅要考虑功能,还需注重扩展性、可读性和其他各种特性。
摘要由CSDN通过智能技术生成

纯java实现记事本

先看结果图:
在这里插入图片描述
程序结构:

在这里插入图片描述
Accelerator类 (添加快捷键)
Accelerator类代码:

public class Accelerator {
   
    public static List<KeyStroke> keyStrokes = new ArrayList<>();
    //keyStroke1 Ctrl+N (新建)
    public static KeyStroke keyStroke1 = KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke2 Ctrl+Shift+N (新窗口)
    public static KeyStroke keyStroke2 = KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    //keyStroke3 Ctrl+O (打开)
    public static KeyStroke keyStroke3 = KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke4 Ctrl+S (保存)
    public static KeyStroke keyStroke4 = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke5 Ctrl+Shift+S (另存为)
    public static KeyStroke keyStroke5 = KeyStroke.getKeyStroke(KeyEvent.VK_S, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    //keyStroke6 Ctrl+P (打印)
    public static KeyStroke keyStroke6 = KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK);

    //keyStroke7 Ctrl+Z (撤销)
    public static KeyStroke keyStroke7 = KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke8 Ctrl+X (剪切)
    public static KeyStroke keyStroke8 = KeyStroke.getKeyStroke(KeyEvent.VK_X, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke9 Ctrl+C (复制)
    public static KeyStroke keyStroke9 = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke10 Ctrl+V (粘贴)
    public static KeyStroke keyStroke10 = KeyStroke.getKeyStroke(KeyEvent.VK_V, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke11 Ctrl+D (删除)
    public static KeyStroke keyStroke11 = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke12 Ctrl+E (使用bing搜索)
    public static KeyStroke keyStroke12 = KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    //keyStroke13 Ctrl+F (查找)
    public static KeyStroke keyStroke13 = KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    //keyStroke14 F3 (查找下一个)
    public static KeyStroke keyStroke14 = KeyStroke.getKeyStroke(KeyEvent.VK_F3, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK);
    //keyStroke15 Shift+F3 (查找上一个)
    public static KeyStroke keyStroke15 = KeyStroke.getKeyStroke(KeyEvent.VK_F3, KeyEvent.SHIFT_DOWN_MASK);
    //keyStroke16 Ctrl+H (替换)
    public static KeyStroke keyStroke16 = KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke17 Ctrl+G (转到)
    public static KeyStroke keyStroke17 = KeyStroke.getKeyStroke(KeyEvent.VK_G, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke18 Ctrl+A (全选)
    public static KeyStroke keyStroke18 = KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke19 F5 (时间/日期)
    public static KeyStroke keyStroke19 = KeyStroke.getKeyStroke(KeyEvent.VK_F5, KeyEvent.CTRL_DOWN_MASK);

    //keyStroke19 Ctrl++ (放大)
    public static KeyStroke keyStroke20 = KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_DOWN_MASK);
    //keyStroke19 Ctrl+- (缩小)
    public static KeyStroke keyStroke21 = KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, KeyEvent.CTRL_DOWN_MASK);
    //key
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值