I am making a recreation of Space Invaders in Java and I want to create a delay between the missiles of my spaceship. @Override public void keyPressed(KeyEvent e) { int key = e.getKeyCode(); // TODO Auto-generated method stub if (key == KeyEvent.VK_LEFT&&n.boom==0) { left=true; } if (key == KeyEvent.VK_RIGHT&&n.boom==0) { right=true; } if (key == KeyEvent.VK_SPACE&&n.boom==0) { space=true; } } @Override public void keyReleased(KeyEvent e) { // TODO Auto-generated method stub int key = e.getKeyCode(); // TODO Auto-generated method stub if (key == KeyEvent.VK_LEFT) { left=false; } if (key == KeyEvent.VK_RIGHT) { right=false; } if (key == KeyEvent.VK_SPACE) { space=false; } } @Override public void keyTyped(KeyEvent e) { // TODO Auto-generated method stub } In my code, space is a boolean variable that when it's true then it creates a new "missile" in another function. All the code works in a while(true) loop that makes everything move. The problem is that if I use some kind of thread.sleep it will stop all the game.