Advertisement

[java] Repaint in Java 2

Started by April 04, 2000 02:10 PM
0 comments, last by javanerd 24 years, 8 months ago
I just noticed that in Java 2 the painting doesn't work in a java.awt.Component subclass with the following code:

// Somewhere in the code we get the graphics object
m_componentGraphics.getGraphics();

// Draw the new frontbuffer to the screen
m_componentGraphics.drawImage( m_frontBuffer, 0, 0, null );
 
But for some reason if I make my graphics engine a subclass of java.awt.Canvas everything works again. The above code works just fine in Java 1.1 within a Component subclass. It smells like something has been changed in the AWT's peer system between Java 1.1 and Java 2. Does anyone know what causes this behaviour? Edited by - javanerd on 4/4/00 2:10:40 PM
-Pasi Keranen
java.awt.Component doesn''t have a drawImage method. If those two lines are your actuall code, then it is simply a matter of doing
Graphics m_componentGraphics = m_component.getGraphics();
The graphics class does not have a getGraphics() methods.

If that is not really your problem, the only thing I can think of is that Canvas'' paint() overrides Component''s paint. There might be a difference there. Also, try java.awt.Component.updateImage() instead of java.awt.Graphics.drawImage(); That might do the trick.

This topic is closed to new replies.

Advertisement