title: Moving multiple scenes in JavaFX
body: <p>I'm in the middle of making an JavaFX application and I have a question. My app has 6 scenes and in every one of them I copy and paste the same code responsible for moving a scene by mouse. This is my code:</p>
  
  <pre><code>//some class instance
  public static double xOffset = 0;
  public static double yOffset = 0;
  
  scene.setOnMousePressed(new EventHandler&lt;MouseEvent&gt;() {
          @Override
          public void handle(MouseEvent mouseEvent) {
              xOffset = mouseEvent.getSceneX();
              yOffset = mouseEvent.getSceneY();
          }
      });
  
      scene.setOnMouseDragged(new EventHandler&lt;MouseEvent&gt;() {
          @Override
          public void handle(MouseEvent mouseEvent) {
              stage.setX(mouseEvent.getScreenX() - xOffset);
              stage.setY(mouseEvent.getScreenY() - yOffset);
          }
      });
  </code></pre>
  
  <p>But im curious, is there any way to not copy/paste the same code in every controller for each scene? Can I just do something to write this code once and make any reference to it in every controller or something like this?</p>