dyerac  
dyerac In Java
公告

日历
<2007年7月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234
统计
  • 随笔 - 36
  • 文章 - 10
  • 评论 - 94
  • 引用 - 0

导航

常用链接

留言簿(5)

随笔分类(49)

随笔档案(36)

文章分类(11)

文章档案(10)

相册

dyerac

搜索

  •  

积分与排名

  • 积分 - 77964
  • 排名 - 707

最新随笔

最新评论

阅读排行榜

评论排行榜

 

* 一个使用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... 阅读(363) 评论(0)  编辑  收藏 所属分类: JavaSE

只有注册用户登录后才能发表评论。


网站导航:
 
 
Copyright © dyerac in java... Powered by: 博客园 模板提供:沪江博客