title: Drawing a straight line with JavaFX
body: <p>I am trying to implement an application that looks like Paint with JavaFX. I'm trying to draw a line first between a(x0,y0) b(x1,y1), but the line only shows up on the canvas after I release the left mouse button.</p>
  
  <p>When I try to use MouseEvent._MOUSE_DRAGGED to solve that problem, many lines are drawn for as long as I am holding the left mouse button.</p>
  
  <p>I am trying to make it more natural like Paint, that you can drag the line around the screen but it is only drawn on the canvas when I release the left mouse button.</p>
  
  <pre><code>Canvas c;
  GraphicsContext gc;
  GeometricObject go;
  ColorPicker colorPicker;
  Button drawLine, drawRectangle;
  TextField defineWidth;
  private boolean isDrawLine, isDrawRectangle;
  double initX = 0, initY = 0, finalX = 0, finalY = 0, width;
  
  private void actionHandler(ActionEvent event) {
      if (event.getSource().equals(drawLine)) {
          isDrawLine = true;
      }
  }
  
  private void pressHandler(MouseEvent me) {
      initX = me.getX();
      initY = me.getY();
  }
  
  private void releaseHandler(MouseEvent me) {
      gc.strokeLine(initX, initY, finalX, finalY);
  }
  
  private void moveHandler(MouseEvent me) {
      finalX = me.getX();
      finalY = me.getY();
      gc.setFill(colorPicker.getValue());
      gc.setLineWidth(1);
  
  }
  </code></pre>
  
  <p>I thought about storing the lines being drawn while the mouse is being dragged in an ArrayList and then delete all of them but the last one that would be drawn when I released the left mouse button...</p>