freelanceprogrammers.org Forum Index » Java
Double-buffering problem
Joined: 17 Apr 2004
Posts: 28
Double-buffering problem
I`m trying to write a game in Java. I primarily use Linux and for some
reason Java images in Linux flicker badly. I`m trying to find a way
around this so that my images don`t flicker. I`d like to use
double-buffering, but I can`t get it to work right with a Java
application. I`m trying to use it in a subclass of Canvas. I typed up
a test example:
import java.awt.*;
public class dbExample extends Canvas
{
Graphics offscreen;
Image image;
public dbExample()
{
image = createImage(500, 500);
offscreen = image.getGraphics();
}
public void paint(Graphics g)
{
offscreen.setColor(Color.cyan);
offscreen.fillRect(0, 0, 400, 400);
g.drawImage(image, 0, 0, this);
}
public static void main(String args[])
{
new dbExample();
}
}
It compiles just fine, but when I try to run it, I get this error:
Exception in thread "main" java.lang.NullPointerException
at dbExample.<init>(dbExample.java:11)
at dbExample.main(dbExample.java:24)
Line 11 is offscreen = image.getGraphics();
Line 24 is just my instantiation of a dbExample object. I want to use a
Canvas because the class I`m working on is just one part of the game and
I need something that can be added to a panel in the calling class.
I`ve gotten double-buffering to work with a JFrame, a JWindow, and an
applet. Can anyone help me???
-Michael Sullivan
All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







