Summary Steps (Cont’d)
// has the component been resized?
if ((curD.width != size().width) || (curD.height != size().height)) {
osImg = createImage (curD.width, curD.height);
osG = osImg.getGraphics();
-in the remainder of paint(), draw the canvas/component as normal, but use osG rather than g as the Graphics object on which to draw. Then at the end of paint():
// make changes to off-screen graphics visible on screen
g.drawImage (osImg,0,0,this);