Painting question
Hello guys,
Here is my situation:
I have a jpanel with a plot , drawn using paintComponent() method, of some math. function.
Now I would like to add to this panel another plot.
Is it possible to paint just the new plot without repainting the old one ?
If yes how ?
[301 byte] By [
maf69a] at [2007-10-2 21:07:55]

Isn't all your painting code (old and new) under "paintComponent()?If you want to replace the old one with the new one, you just need a "isNew" boolean varaible there .. Another solution is using anothe Jpanel, which may be a better design
I paint one plot in paintComponent() method.
For one plot I have one ArrayList of it's points to draw.
The thing is that I would like to add many plots to one panel.
For example, the user pressed the button to draw the first plot.
Then the user pressed a button to draw another plot, on the same panel,
so both plots are visible.
I can see one way to do it:
I need to have a field in my class - an array X - which holds under position 0
an ArrayList with points of plot 1 , then under position 1 there is an ArrayList with points of
plot 2 etc. Then in paintComponent() method I have to go through
the array X and draw all the points in every ArrayList.
Now my question is : can the same result be done in other way ? So I
don't need to draw all the points of all plots every time the new plot is added
but just to draw only the new plot ?
Well I guess there isn't but just want to check if I'm right :-)
Regards
maf69a at 2007-7-13 23:53:39 >

You could use a BufferedImage as a back-buffer, but I don't think you'd gain much.
By the way, it may be worth using a Shape (probably GeneralPath) rather than a List of points. Basically, since the ability to draw a series of lines is already in the standard libraries, why reproduce it?