I have a clear button which seems to work..but actually its not. When I click back on the canvas I can see the drawing.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no problem in the way you are clearing the canvas, the problem lies in your logic.
Everytime you
clickor move the mouse theaddClickmethod is called, which populates the arraysclickX,clickYandclickDragwith the coordinates; and then theredrawmethod is called which plots the points on thecanvas.So when you clear the
canvasyou are failing to reset these arrays, so when theredrawmethod is called again (after clearing the canvas), the old points get plotted too.So try emptying the arrays
clickX,clickYandclickDragas shown below, when you clear yourcanvas; so that the old points are not considered when you start fresh.