title: How to rotate something upwards based on mouse position in Java
body: <p>Good afternoon guys, I'm trying to rotate an polygon based on my mouse position, but I can't figure out how to rotate the polygon upwards based on my mouse y. I'm using MouseMotionListener. I've tried to do this until now:</p>
  
  <pre><code>    public void mouseMoved(MouseEvent m){
               int yantes= m.getY();
               while (true){
                  int y = m.getY();
                  repaint();
                  if (y - yantes &gt; 0){
                    rotation++;
                    if (rotation &gt; 360) rotation = 0; 
                    repaint();
                    break;    
                  } else {
                      rotation--;
                      if (rotation &lt; 0) rotation = 359; 
                      repaint();
                      break;  
                  }
              }
  
          }
  </code></pre>
  
  <p>The yantes variable tries to calculate the y before the move, and y the y in after the movement.</p>