So what have you tried so far? Where exactly are you stuck?
The problem can be broken down to
-- detecting mouse events
-- custom painting
-- storing already drawn graphics for repeat, OR
-- drawing to an offscreen buffer
As I don't suppose you expected someone to write the entire code for you, do please help us to help you by being more specific about your needs.
Reading
this page might help you to ask your question in a better way!