title: Multiple Keylisteners Java
body: <p>currently im trying to code a grid based game.
  ive already managed to implement a key listener for general navigation. 
  but when pressing a certain key, a Jpopup Menu opens.</p>
  
  <p>now i want to implement navigation for the menu aswell with a key listener. Pressing B is supposed to close the menu again. </p>
  
  <pre><code>  KeyListener  UnitActionMenuKeyListener =   new KeyListener()          { 
      @Override
      public void keyPressed(KeyEvent evt) 
      {
  
      if (evt.getKeyCode()==KeyEvent.VK_B)
  
          menu.setVisible(false)
      }
  
      @Override
      public void keyReleased(KeyEvent arg0) {
          // TODO Auto-generated method stub
  
      }
  
      @Override
      public void keyTyped(KeyEvent arg0) {
          // TODO Auto-generated method stub
  
      JPopupMenu menu = new JPopupMenu("UnitActionMenu");
      JMenuItem bewegenItem = menu.add("test");
  </code></pre>
  
  <p>Using menu.show and menu.addKeyListener after this.</p>
  
  <p>But no matter what i try, either my general navigation wont work anymore, or the general navigation will work, but my menu wont react to pressing B</p>
  
  <p>so, how do i implement multiple key listeners for multiple elements?
  i just want my main window to listen (and react) to some key differently than my menu</p>
  
  <p>(sorry for bad writing, my english isnt that good and im frustrated by failing a simple task for more than 4 hours)</p>