I had asked the same question at stackoverflow but didn't got any useful tips. The only difference is that here I have changed the JApplet to JFrame.
Stackoverflow Link
What I need to do in program :There are total 2 buttons
Circle and
Square. When a user clicks on
Circle button, the counter should count the number of times the
Circle button has been clicked and draw that many circle. Thats fine. Now when the user clicks on
Square button same thing should happen i.e. counting and drawing the squares and it works fine.
Now when again the user clicks on
Circle button then the problem is that the previous circles drawn gets disappeared and it again starts from one.
Here's the code.