纯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