How the User Blocks Pucks
The computer moves its own blocker around, but the user is responsible for moving his blocker using the mouse. To handle the mouse, you'll need to catch mouse press, mouse drag, and mouse release events, which are handled by implementing the methods of the MouseListener and MouseMotionListener interfaces, as you've already seen.
When the user presses the mouse, Slapshot! checks to see if the mouse is over his blocker, and if so, sets a Boolean flag named dragging to true, which means that from then on the user can drag his blocker simply by moving the mouse.
When the user presses the mouse, the mousePressed method is passed a MouseEvent object, and you can use the getX and getY methods of that object to determine where ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access