Reputation:
How to make pencil-drawing on a JPanel via mouseDragged ?
I have a JPanel where I want to draw using the mouse, so whenever I drag the mouse on that JPanel, for each (x,y) an oval shape (with specified color and dimension) is painted.
Upvotes: 1
Views: 228
Reputation: 324108
There are two common ways to do custom painting:
Create a List of Objects you want to paint and then iterate through the List every time the component is repainted.
Paint the objects directly to a BufferedImage and then when the component is repainted you paint the BufferedImage.
Check out Custom Painting Approaches for working examples of both approaches. The example actually draws colored Rectangles which is almost exactly what you want.
Upvotes: 1