DoubleBuffering Problem

Hi, I’m new here and trying to develop a game in Java
using an application that contains a Canvas class.

I use double buffering with two Graphics objects
g and gImage.

The problem is, with my addition of the mouseMotionListener
my program flickers a lot (since mouseMoved() calls repaint())

My tetris program that I am doing for a class works fine with
double Buffering. I think the problem with this one is that I use png
images in my program.

Any thoughts or suggestions would be greatly appreciated.

~Phoenix412

type of the objects?
some code?
are you sure you are using double buffering correctly?

	
public void paint(Graphics g)
{
		// sets up logical coordinate orientation
		init();

		// sets up double buffering gImage
		image = createImage((maxX+1), (maxY+1));
		gImage = image.getGraphics();
		gImage.clearRect(0,0,maxX+1,maxY+1);

...//all modifications are made to gImage

g.drawImage(image, 0, 0, null);

the images are all made using this code and toolkit
enemyPic, background, player1test are all Image objects


		t = Toolkit.getDefaultToolkit(); // define a Toolkit
		enemyPic = t.createImage("WillTest.png"); // load the image
		background = t.createImage("backTest.png"); // load background
		player1Pic = t.createImage("player1Test.png");

and here’s my mouse listener code:


		addMouseMotionListener(new MouseAdapter()
		{ public void mouseMoved(MouseEvent e)
			{
				int X = e.getX(); int Y = e.getY();

				if (X > enemyFrameX && X < (enemyFrameX + enemyFrameWidth) && Y > enemyFrameY && Y < (enemyFrameY + enemyFrameHeight) ) // if mouse is on main area
				{
					hoverEnemy = true;
				}
				else
				{
					hoverEnemy = false;
				}
				repaint(enemyFrameX-5, enemyFrameY+5, enemyFrameWidth+10, enemyFrameHeight+10);
			}
		});

the repaint gets called everytime the mouse is moved, so it flickers quite frequently…

If you are using active rendering then don’t call the repaint in mouse moved and have it just wait till the next tick. If you are not using active rendering you will probably need to change it to only repaint when the hover value has changed.


How do I know which one I’m using
and what’s the difference between the two?

EDIT: It looks like I’m not using active rendering. I tried not calling repaint()
but my desired outcome (framing the enemy window in yellow to show you are hovering)
does not happen correctly.

After more fiddling, I found out that it was my thread that was not working correctly.
I AM using active rendering, so the previous suggestion worked.
and I was missing the update() method upon further inspection.
Thanks for the help.