i have written a program in which i am drawing using a mouse. however while drawing a new line the previous ones are still being shown. i have called repaint every time the mouse is moved.
Can anyone please help.

At the start of the paint method, call super.paintComponent. This should have the effect of clearing the screen. If it doesn't, draw a new rectangle on the screen that is the color you want (white or gray probably) that fills the whole screen.

thank you. the super.paintComponent method worked

Yep, no problem. Somebody else on this forum told me that solution a while back as well. Also, mark this thread as solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.