title: Handling multiple events at the same time with JavaFx
body: <p>I'm new to javaFx, and I want to create a griddles-like game.
  First thing I want to do is to understand how the event handling works.</p>
  
  <p>So, I created a simple board of rectangles and attached each rectangle with MouseEvent and an event handler iv'e created.</p>
  
  <p>What I wanted to do is :
  if the event is left mouse click, paint the rectangle in,
  else if the event is MouseEnter and the left mouse is already pressed, paint the current rectangle in red.</p>
  
  <p>I thought it should be pretty basic but when i implemented this I get only mouse pressed and entered on the first rectangle I click and mouse enter on the last rectangle when I dismiss the left mouse click..</p>
  
  <p>this is the event handler class :</p>
  
  <pre><code>    public void handle(MouseEvent event) {
      if(event.getEventType().equals(MouseEvent.MOUSE_PRESSED)) {
          System.out.println("Pressed on " + row + ", " + col);
      } else if (event.getEventType().equals(MouseEvent.MOUSE_ENTERED)) {
          System.out.println("Entered " + row + ", " + col);
      }
  }
  </code></pre>
  
  <p>and this is where I attach the event :</p>
  
  <pre><code>    private void addRectangles() {
      for (int row = 0; row &lt; rows; row++) {
          for (int col = 0; col &lt; cols; col++) {
              Rectangle rectangle = new Rectangle(col * CELL_SIZE, row * CELL_SIZE, CELL_SIZE, CELL_SIZE);
              rectangle.setStroke(Color.WHITE);
              rectangle.addEventHandler(MouseEvent.ANY, new ShapeColorChanger(row, col, rectangle));
              getChildren().add(rectangle);
          }
      }
  }
  </code></pre>
  
  <p>So, if i'm pressing a rectangle in 0,0 and dragging the mouse to rectangle 0,3 (while going over rectangles at 0,1 and 0,2) I get this output : </p>
  
  <p>Entered 0, 0</p>
  
  <p>Pressed on 0, 0</p>
  
  <p>Entered 0, 3</p>