dyerac  
          dyerac In Java
          公告

          日歷
          <2007年7月>
          24252627282930
          1234567
          891011121314
          15161718192021
          22232425262728
          2930311234
          統計
          • 隨筆 - 36
          • 文章 - 10
          • 評論 - 94
          • 引用 - 0

          導航

          常用鏈接

          留言簿(5)

          隨筆分類(49)

          隨筆檔案(36)

          文章分類(11)

          文章檔案(10)

          相冊

          dyerac

          搜索

          •  

          積分與排名

          • 積分 - 79790
          • 排名 - 705

          最新隨筆

          最新評論

          閱讀排行榜

          評論排行榜

           

          * 一個使用KeyStroke自定義快捷鍵的示例
           * 
          */
          public class MnemonicT extends JFrame {
           private int count = 0;

           private JButton button;

           public MnemonicT() {
            super("Mnemonic Test");
            JPanel panel = new JPanel();
            panel.setPreferredSize(new Dimension(320, 240));
            panel.setLayout(new FlowLayout());

            button = new JButton(new AbstractAction("ClickTimes:" + count) {
             public void actionPerformed(ActionEvent e) {
              button.setText("ClickTimes:" + (++count));
             }
            });
            panel.add(button);
            add(panel);

            InputMap im = button.getInputMap(JButton.WHEN_IN_FOCUSED_WINDOW);
            im.put(KeyStroke.getKeyStroke("control A"), "buttonAction"); // 按CTRL+A
            button.getActionMap().put("buttonAction", button.getAction());
            pack();
            setDefaultCloseOperation(EXIT_ON_CLOSE);
           }

           public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
             public void run() {
              new MnemonicT().setVisible(true);
             }
            });
           }
          }

          posted on 2007-07-24 11:06 dyerac in java... 閱讀(398) 評論(0)  編輯  收藏 所屬分類: JavaSE
           
          Copyright © dyerac in java... Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 南城县| 敦煌市| 锦屏县| 永昌县| 清丰县| 克拉玛依市| 靖宇县| 德江县| 调兵山市| 当阳市| 安龙县| 新田县| 兴安县| 合山市| 琼结县| 德庆县| 四会市| 微山县| 古蔺县| 三亚市| 京山县| 永清县| 瓦房店市| 德惠市| 石阡县| 威海市| 波密县| 枣庄市| 密山市| 杭州市| 阿克苏市| 诸城市| 勐海县| 二手房| 扶沟县| 香格里拉县| 浙江省| 平潭县| 凤城市| 辉南县| 汾西县|