Java AWT applet white screen when resizing window
I have a java applet built using awt.
I draw some text on a panel object and everything goes fine. but when resizing the windows all the text disappears.
this behaviour is开发者_如何学编程 different among different jvms and platforms.
moving to swing isn't a possible option, because we have to maintain compatiblty with Microsoft JVM.
You must override update(Graphics g)
and render your text in there. This method will be called when the window needs to be redrawn.
Without seeing your code, we have to guess, but is it possible that your text drawing is not being done in a paint()
method? Read this for details on how AWT painting works.
Try attaching a ComponentListener which then calls paint() from within componentResized().
Something like:
class MyPanel extents Panel implements ComponentListner {
public MyPanel() {
addComponentListener(this);
}
public void componentResized(ComponentEvent e) {
paint(getGraphics());
}
}
Update: you should probably call 'repaint()' rather than directly invoking paint().
精彩评论