java swing: previous paintings disappear
Hi,
an oval is created in graphArea (a JPanel) on mouseClicked. However, as soon as the mouse is clicked for the second (n-th) time, the first (previous) oval disappears and another oval appears on the new location. How can i keep the old the new ovals, too? In general, how can i keep the old painted components and the new ones? (It has probably something to do with the repaint(), but i don't know what...) A hint? Code:
import java.awt.*; |
Here it is...
Method repaint() clears the background. However, method updateUI() of JPanel, must be implemented on method update() of JComponent, which doesn't clear the background. Code:
graphArea.addMouseListener(new MouseAdapter() |
The only sure way to add multiple items to be displayed - and then to make sure they're all displayed each and every time the panel is refreshed (expose event, minimize/maximize, resize, etc) is:
a) Make a list of your graphics entities (an array, one or another Java container - etc) b) Iterate through that list in your "paint()" method |
I did not understand the whole question, but I wrote this and it will keep the previous Oval thing. Is this what you were looking for?
Code:
import javax.swing.*; |
Hi Mega Man X,
you understood right. The repaint() does indirectly exactly what updateUI() and update() does. From the API: Quote:
|
All times are GMT -5. The time now is 10:34 PM. |