Handling the Mouse
Each figure is defined by a “mouse pressed” action, which sets a point named start, and a “mouse released” action, which sets a point named end. When the mouse is released, any figure Painter is capable of drawing can be drawn—including a line, rectangle, ellipse, and so on—because start and end define the region in which the figure should be drawn.
When the user presses the mouse, the mouse position is recorded in the start point, and a flag indicating the state of the mouse, mouseUp, is set to false. While the user drags the mouse, Painter will draw the current graphics figure, expanding or reducing it to follow the mouse movements interactively. To translate between window coordinates (used when the mouse is being dragged) ...
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