-
Repaint - flickerings
Hi,
I'm having a little problem with a Java applet .. no idea if it's solvable or if this is just the way Java applets look like. Me new to JAVA .. so me no experience to rely on :D
Anyways ..
This is the applet in question. Forget the content of the fields - the pictures and the text are just placeholding bogus for now. The fields should change their color when the mouse moves over them. I do that by constantly monitoring the mouse coordinates .. and saving them. Next time the coordinates are captured, I compare them with the last ones .. if the old ones are outside the box and the new ones are inside, the color with which I drew the ractangle is changed .. and I use the command "repaint()"
The problem .. it flickers. Too much. Is there a different way with which I can draw graphics outside of the paint method that doesn't cause this kind of flickering? Or is there a way to repaint only a limited part of the screen? Or any other way in which I could improve this?
Thanks,
Jeremy
-
Try Double buffering. The idea is to paint on a rendered image, then paint the image.
http://www.javaworld.com/javaworld/j...l#doubleBuffer
-
Got it to work .. thanks a lot :D
One tiny problem I had with this was that it would not paint the first frame until I click my mouse for the first time .. I solved this problem by defining a int that I set 0 .. and in my
public void mouseEntered( MouseEvent e )
tell the computer to repaint if that variable is 0 and to then set the variable to 1 again. Which means .. I get a picture as soon as the mouse is over the applet space. Since the applet space is the whole screen .. this is okay. I was just wondering though .. if there is a more efficent/orthodox/common way to make sure that the first frame is drawn. No catastrophy if there isn't, it's fine as it is :D
-
why not just tell it to repaint whenh youre done pre-processing
-
the void paint(Graphics g) is called right after the applet is inited.
post your first picture code there.