0

When I first used ActionListener, it was with JButtons. We used to setActionCommand("blah") for every button. Then, in actionPerformed(ActionEvent e), we used something that looked like this if(e.getActionCommand().equals("blah")) //do something. However, with key bindings, since I am using the same component, there is no point to setActionCommand. ActionEvent now seems useless. Can you set a key to an actionCommand?

Ilann
  • 3
  • 4
  • 1
    You could use `KeyListener` instead. – QBrute May 01 '16 at 12:54
  • An action can have a key combo. associated with it, and a [button can be constructed from an action](http://docs.oracle.com/javase/8/docs/api/javax/swing/JButton.html#JButton-javax.swing.Action-). That answers your question as best I understand the question (which is 'not much'). – Andrew Thompson May 01 '16 at 13:10
  • `e.getActionCommand() == "blah"` And that is not how to [compare strings in Java](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java). – Andrew Thompson May 01 '16 at 13:10

0 Answers0