The Coder's Handbook
Mouse and Keyboard
Note: In the example above, note that we need to check mousePressed. This is because mouseButton simply stores the last button that was pressed - even if it's been a long time. It doesn't tell us anything about whether the button is still down or not.
Chapter 3.3, 3.4 - Mouse and Key Events