0

checkout the first answer of this post: Java Keybindings especially, these rows:

am.put("RightArrow", new ArrowAction("RightArrow"));
am.put("LeftArrow", new ArrowAction("LeftArrow"));
am.put("UpArrow", new ArrowAction("UpArrow"));
am.put("DownArrow", new ArrowAction("DownArrow"));

he is always creating new object of his class, is it possible to do without it? check my code below, I tried all methods of ActionEvent's variable "e", but all of them were unuseful. Is it good to create every time new object? I have this so far:

action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
        // can I determine here what action was performed?
        }
    };

    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), "left_arrow");
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), "right_arrow");
    actionMap.put("left_arrow", action);
actionMap.put("right_arrow", action);
Community
  • 1
  • 1
Pink
  • 431
  • 2
  • 9
  • 18

0 Answers0