datalogo
Return to Unit Menu |  JavaBitsNotebook.com | MathBits.com | Terms of Use  | JavaMathBits.com

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

mouseclick2a
mouseclick2b

rc1    pic2

dividerdash

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.

pic3A
circlewhitecode

whitewircles

• 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
super.paintComponent(g);

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

divider
Return to Unit Menu |  JavaBitsNotebook.com | MathBits.com | Terms of Use  | JavaMathBits.com

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, JavaMathBits.com.
Help us keep these resources free. Thank you.