title: Calling method using KeyBindings
body: <p>I'm creating a 2d game, where the players can shoot bullets. I'm trying to figure out how to call the shoot method when a player presses a key. I'm using Key Bindings, which is new to me. I have read the API but still can't get it work. Suggestions would be helpful</p>
  
  <p>Here is my code for Keyboard input: </p>
  
  <pre><code>public PlayerTwo (){
      playertwo = Toolkit.getDefaultToolkit().createImage("cal.png");
      bullets = new ArrayList();
      tm.start();
      InputMap im = getInputMap(JPanel.WHEN_IN_FOCUSED_WINDOW);
      ActionMap am = getActionMap();
  
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, false), "up.pressed");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0, true), "up.released");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, false), "down.pressed");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0, true), "down.released");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, false), "left.pressed");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0, true), "left.released");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, false), "right.pressed");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0, true), "right.released");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false), "space.pressed");
      im.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true), "space.released");
  
  
      am.put("up.pressed", new MoveAction(-1, 0));
      am.put("up.released", new MoveAction(0, 0));
      am.put("down.pressed", new MoveAction(1, 0));
      am.put("down.released", new MoveAction(0, 0));
      am.put("left.pressed", new MoveAction(0, -1));
      am.put("left.released", new MoveAction(0, 0));
      am.put("right.pressed", new MoveAction(0, 1));
      am.put("right.released", new MoveAction(0, 0));
      //Shoot.getActionMap();
  
  }
  </code></pre>