dyerac  
          dyerac In Java
          公告

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

          導航

          常用鏈接

          留言簿(5)

          隨筆分類(49)

          隨筆檔案(36)

          文章分類(11)

          文章檔案(10)

          相冊

          dyerac

          搜索

          •  

          積分與排名

          • 積分 - 79492
          • 排名 - 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: 博客園 模板提供:滬江博客
          主站蜘蛛池模板: 怀集县| 汝阳县| 清河县| 汕头市| 平阳县| 五华县| 皋兰县| 女性| 云南省| 长汀县| 繁昌县| 芜湖县| 珲春市| 南昌市| 都昌县| 七台河市| 卫辉市| 峡江县| 紫云| 眉山市| 巢湖市| 和静县| 北碚区| 巴彦县| 桑植县| 滨海县| 南漳县| 汽车| 咸丰县| 丘北县| 兰坪| 辽宁省| 南雄市| 兰州市| 青海省| 威宁| 班戈县| 屏山县| 筠连县| 潜江市| 寿光市|