dyerac  
          dyerac In Java
          公告

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

          導航

          常用鏈接

          留言簿(5)

          隨筆分類(49)

          隨筆檔案(36)

          文章分類(11)

          文章檔案(10)

          相冊

          dyerac

          搜索

          •  

          積分與排名

          • 積分 - 79480
          • 排名 - 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... 閱讀(396) 評論(0)  編輯  收藏 所屬分類: JavaSE
           
          Copyright © dyerac in java... Powered by: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 新安县| 双城市| 陵水| 陕西省| 开化县| 如皋市| 山西省| 泸水县| 安吉县| 玉溪市| 关岭| 瑞昌市| 广丰县| 寿光市| 饶平县| 峨眉山市| 民和| 故城县| 涿州市| 和田县| 彰化市| 泽州县| 嵩明县| 德州市| 巴林左旗| 新和县| 加查县| 洞口县| 海盐县| 孝昌县| 新沂市| 江川县| 长春市| 新邵县| 石屏县| 晋州市| 绍兴县| 丰城市| 武平县| 长汀县| 长兴县|