In the following code faFreqAmpValues is an array containing values between 0 and 1, and fTimeXValue is initialised to 0.
My question is why does everything that was previously drawn seem to be erased every time the paint method is called, and is there a way to prevent this?
void DisplayComponent::paint (Graphics &g)
g.drawHorizontalLine(i, fTimeXValue, fTimeXValue+1);
er… because that’s how all computer graphics has been done since the 1980s…
If you want to keep drawing onto the same image, you can just create your own Image object and draw onto it as much as you like.
If you want to keep drawing onto the same image, you can just create your own Image object and draw onto it as much as you like.[/quote]
Does this mean that I create the Image object outside the paint method that covers a certain part of the component , and from there I can use the Graphics object in the paint method to draw lines on top of it that will remain?
A Graphics object is already assigned to a target; if you use the one in the paint function, you are drawing to the component directly [which will always start blank].
You’d create your own image somewhere, and create your own Graphics object to draw to it. You would then draw that image onto the component using the Graphics instance provided to the paint callback.