Return to Unit Menu | | | Terms of Use  |

Mouse Click Drawing (PART 2)
See Part 1
PART 2: At each new mouse click, a duplicate circle will appear.
No circles will disappear.

To accomplish a display where a duplicate circle will appear after each mouse click (and no circles disappear) we have several options. We will take a look at two of these options: an option utilizing arrays for storage and an option with adjusted coding.

Array Option


rc1    pic2


Adjusted Coding Option

You will notice that this example is exactly the same as the Part 1 example (where the old circles disappeared), except for 3 lines. Two lines have been removed and one line has been added. This example will let you see how the super.paintComponent line affects the JPanel. With the indicated adjustments, this example will now leave the old circles visible.



• The line
super.paintComponent(g); was removed
which allows the previously drawn circles to remain.

• The line
setBackground(Color.WHITE); was removed
because it is not supported for a JPanel without

• the
f.setBackground(Color.WHITE); was added in main
so we are now painting the JFrame background white (instead of the JPanel).

Return to Unit Menu | | | Terms of Use  |

Notice: These materials are free for your on-line use at this site, but are not free for the taking.
Please do not copy these materials or re-post them to the Internet, as it is copyright infringement.
If you wish hard-copies of these materials, refer to our subscription area,
Help us keep these resources free. Thank you.