Need Help with Paint Proccess
Need help with a java project. My java application draws animated 2D objects in a canvas using BufferStrategy. Upon certain events I want to open another Frame; Frame A opens Frame B and draw objects into Frame B from Frame A's paint process. Not sure what I am doing wrong but it will not display what was drawn in Frame B unless I set focus to Frame B. I need to paint to Frame B and have it shown without changing focus to it.
Example;
// MyCanvasClass - Used for Frame A and Frame B
publicvoid paint(Graphics g){
if (this.frame == FrameB)
this.requestFocus();
if ( bimg ==null){
createBufferStrategy(2);
bimg = getBufferStrategy();
g2 = (Graphics2D)bimg.getDrawGraphics();
clearcanvas =true;
}else
g2 = (Graphics2D)bimg.getDrawGraphics();
render(g2);
bimg.show();
if ( clearcanvas){
clearcanvas =false;
}
toolkit.sync();
// If Primary Frame and Frame B has been drawn too, repaint it.
if (this.frame != FrameB && FrameB.dirty ==true){
FrameB.canvas.repaint();
FrameB.dirty =false;
}
}
publicvoid update(Graphics g){
if (this.frame == FrameB)
this.requestFocus();
if (clearcanvas){
super.update(g);
}else{
if ( bimg ==null){
createBufferStrategy(2);
bimg = getBufferStrategy();
g2 = (Graphics2D)bimg.getDrawGraphics();
clearcanvas =true;
}else
g2 = (Graphics2D)bimg.getDrawGraphics();
Myupdate(g2);
toolkit.sync();
// If Primary Frame and Frame B has been drawn too, repaint it.
if (this.frame != FrameB && FrameB.dirty ==true){
FrameB.canvas.repaint();
FrameB.dirty =false;
}
}
}
Thanks for any help you can provide!
Dave

