title: JavaFx close window on pressing esc?
body: <p>Im calling a new stage in my program which I like to close on pressing escape. I did this which gives me a NullPointerException:</p>
  
  <pre><code>    scene.setOnKeyPressed(new EventHandler&lt;KeyEvent&gt;() {
          @Override
          public void handle(KeyEvent t) {
              KeyCode key = t.getCode();
              if (key == KeyCode.ESCAPE){
                  stage.close();
              }
          }
      });
  </code></pre>