I have define the JPanel
named drawPanel
, and a button named Jbutton1
with an ActionListener
. I want to continue draw something on the drawPanel
after clicked the Jbutton1
. And I do not want to clear the drawPanel
first and draw more things, I just want to continue draw on the drawPanel
and show it in a JFrame
.
Asked
Active
Viewed 118 times
-2

Andrew Thompson
- 168,117
- 40
- 217
- 433

张少华
- 1
-
What does the button have to do with `repaint()`? For better help sooner, post an [MCVE](http://stackoverflow.com/help/mcve) (Minimal Complete Verifiable Example) or [SSCCE](http://www.sscce.org/) (Short, Self Contained, Correct Example). – Andrew Thompson Apr 26 '15 at 09:06
1 Answers
1
Check out Custom Painting Approaches for the two common ways to do this:
- Keep a List of Objects that you want to paint and then iterated through the list every time.
- Paint to a BufferedImage and then just paint the BufferedImage.

camickr
- 321,443
- 19
- 166
- 288