4

这两种方法有什么区别:

getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(
       "pressed F10"), "someAction");

getActionMap().put("someAction", new AbstractAction() {
     @Override
     public void actionPerformed(ActionEvent e) {
          //Do something
     }
});

和:

registerKeyboardAction(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) {
        //Do something
    }
}, KeyStroke.getKeyStroke("pressed F10"), JComponent.WHEN_FOCUSED);
4

1 回答 1

2

没有区别,但是如 javadoc 中所述, registerKeyboardAction 已过时。

于 2014-03-04T16:24:37.500 回答