Reputation: 39
I created a little sketchpad program with basic GUI. I used the paintComponent method. I want to update the graphic being drawn every millisecond. That way, the user can see what they're about to draw before they release the mouse click. For example, if I'm drawing a rectangle, I want to see the rectangle while I'm drawing it. If you're confused as to what exactly I'm talking about, open MS Paint and click on the rectangle tool. Draw a rectangle. Notice how it updates continuously, as opposed to after you release the mouse. I figured that there must be some way I can get it to update my graphics every millisecond. What is the best way to go about doing this? Sorry if this is an easy question, I'm new to Swing! :)
Upvotes: 0
Views: 134
Reputation: 324197
Well you don't update every millisecond.
You use a MouseMotionListener
and you update every time a mouseDragged
event is generated to redraw the Rectangle.
Check out Custom Painting Approaches for two approaches on how to do this.
The examples show how to draw multiple rectangles by either:
Upvotes: 2