title: Java switch case delay
body: <p>I'm programming a little 2d game. Acutally I'm busy with the jumping-function. I want my player to jump, when i press the up-arrow key. I managed to make him jumping, but there is a delay of at least one second. This dealy is not existing for other actions like moving left or right. Do you know where it comes from?</p>
  
  <p>The code for jumping is in the keyReaction method.</p>
  
  <pre><code>public class John&lt;I&gt; extends AbstractGame&lt;I&gt; {
  //lists
  List&lt;ImageObject&lt;I&gt;&gt; floor = new ArrayList&lt;&gt;();
  
  //variables
  double jumpHeight = 0;
  
  //boolean
  boolean jump = false;
  
  //fix values
  int blockHeight = 40;
  int blockWidth = 40;
  
  public John(double width, double height) {
      //getPlayer()
      super(new ImageObject&lt;&gt;("player.png", new Vertex(120, height - 200), new Vertex(0, 0)), width, height);
  
      //floor objects
      for(int i=0; i&lt;getWidth(); i+=blockWidth)
          floor.add(new ImageObject&lt;&gt;("brick.png", new Vertex(i, getHeight() - blockHeight)));
  
      //add arrays to canvas
      getGOss().add(floor);
  }
  
  @Override
  public void doChecks() {
      for(ImageObject&lt;I&gt; f:floor) {
          //gravity
          if(!(jump) &amp;&amp; !(getPlayer().touches(f)))
              getPlayer().getMotion().y++;
  
          //stop y-motion on ground
          if(getPlayer().touches(f)){
              getPlayer().getPos().y = getHeight() - blockHeight - getPlayer().getHeight();
              getPlayer().getMotion().y = 0;}
      }
  }
  
  @Override
  public boolean isStopped(){
      return false;
  }
  
  @Override
  public void keyReaction(KeyCode keycode){
      switch (keycode) {
          //move left
          case LEFT_ARROW:
              getPlayer().getMotion().x = -2;
              break;
          case VK_A:
              getPlayer().getMotion().x = -2;
              break;
          //move right
          case RIGHT_ARROW:
              getPlayer().getMotion().x = 2;
              break;
          case VK_D:
              getPlayer().getMotion().x = 2;
              break;
          //jump
          case UP_ARROW:
              jump = true;
              if(jumpHeight &lt; 100){
                  jumpHeight += 5;
                  getPlayer().getPos().y -=5;
  
              } else if (jumpHeight &lt; 200){
                  jumpHeight +=5;
                  getPlayer().getPos().y +=5;
              }
              break;
          case VK_W:
              break;
          case SPACE:
              break;
      }
  }
  
  @Override
  public void keyReactionReleased(KeyCode keycode){
      switch (keycode) {
          //move left
          case LEFT_ARROW:
              getPlayer().getMotion().x = 0;
              break;
          case VK_A:
              getPlayer().getMotion().x = 0;
              break;
          //move right
          case RIGHT_ARROW:
              getPlayer().getMotion().x = 0;
              break;
          case VK_D:
              getPlayer().getMotion().x = 0;
              break;
          //jump
          case UP_ARROW:
              jump = false;
              jumpHeight = 0;
              break;
          case VK_W:
              jump = false;
              break;
          case SPACE:
              break;
      }
  }
  
  //test main
  public static void main(String[] args) {
      JFrame f = new JFrame();
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      f.add(new SwingScreen(new John&lt;&gt;(1800, 600)));
      f.pack();
      f.setVisible(true);
  }
  }
  </code></pre>
  
  <p>Thank you for your help.</p>
  
  <p>Code with the if:</p>
  
  <pre><code>case UP_ARROW:
      if(jumpHeight &lt; 20){
          jumpHeight += 5;
          getPlayer().getPos().y = -5;
  
      } else if (jumpHeight &lt; 40){
          jumpHeight +=5;
          getPlayer().getPos().y = 5;
      }
      break;
  </code></pre>
  
  <p>Code without the if:</p>
  
  <pre><code>case UP_ARROW:
     getPlayer().getPos().y = -5;
     break;
  </code></pre>
  
  <p>KeyReaction:</p>
  
  <pre><code>setOnKeyPressed((ev)-&gt;{
      logic.keyReaction(KeyCode.fromCode(ev.getCode().impl_getCode()));
      ev.consume();
          });
  
  setOnKeyReleased((ev)-&gt;{
      logic.keyReactionReleased(KeyCode.fromCode(ev.getCode().impl_getCode()));
      ev.consume();
          });
  </code></pre>