title: need help in implementing KeyListener for 2D game in Java
body: <p>i stated coding my first game in java, i need some help in imlementing KeyListener to fit my game. after some search in tutorials i've imlemented it like this :</p>
  
  <pre><code>frame.addKeyListener(new KeyAdapter(){
  
  private boolean[] keys = new boolean[120];
  public boolean up , down , left , right;
  
  
  
  public void tick() {
      up =  keys[KeyEvent.VK_UP] || keys[KeyEvent.VK_W];    
      down =  keys[KeyEvent.VK_DOWN] || keys[KeyEvent.VK_S];  
      left =  keys[KeyEvent.VK_LEFT] || keys[KeyEvent.VK_A];
      right =  keys[KeyEvent.VK_RIGHT] || keys[KeyEvent.VK_D];
  }
  
  public void keyPressed(KeyEvent e) {
      if(e.getKeyCode() != KeyEvent.VK_F5) keys[e.getKeyCode()] = true;
      tick();
      if (up){
          yMap+=4;
          direction='n';
          xInd=0;
      }
      else if(down){
          yMap-=4;
          direction='s';
          xInd=2;
      }
      else if(right){
          xMap-=4;
          direction='e';
          xInd=1;
      }
      else if(left){
          xMap+=4;
          direction='w';
          xInd=3;
      }
      wait++;
      if(wait==5){
          yInd++;
          wait=0;
      }
      if(yInd==3)
          yInd=0;
      cha=sprites[xInd][yInd];
      panel.repaint();
  }
  
  public void keyReleased(KeyEvent e) {
      keys[e.getKeyCode()] = false;
      tick();
      yInd=0;
      cha=sprites[xInd][yInd];
      panel.repaint();
  }
  
  public void keyTyped(KeyEvent e) {  
  }
  });
  </code></pre>
  
  <p>however every thing is fine in this code, the character is moving correctly the sprites are perfect but it is missing only one thing, the only thing i need is when i move the character in a direction, lets say for exemple UP, with a simple click on the up button (which normaly should make it move with only 4 pixels to up), the character should complete walking to the next square automaticaly (each square is 32*32 pixels).</p>
  
  <p>here an exemple, lets say what i have is some thing like this map :</p>
  
  <p><a href="http://i.stack.imgur.com/I6hwj.jpg" rel="nofollow">http://i.stack.imgur.com/I6hwj.jpg</a></p>
  
  <p>the red cercle is the character i wanna move,what i need is when i press UP button the red cercle should go to the next square automatically like this :</p>
  
  <p><a href="http://i.stack.imgur.com/1XPPX.jpg" rel="nofollow">http://i.stack.imgur.com/1XPPX.jpg</a></p>
  
  <p>and it shouldnt stay in the middle !</p>
  
  <p>i hope i explained well my question and sorry for bad english !</p>