Java Applet viewer blinks everytime the init method is used.

Reply

Join Date: May 2004
Posts: 2
Reputation: Radahl is an unknown quantity at this point 
Solved Threads: 0
Radahl Radahl is offline Offline
Newbie Poster

Java Applet viewer blinks everytime the init method is used.

 
0
  #1
May 17th, 2004
I'm currently working on a program that's like target practice. You literally hit...targets! However, the constant blinking that occurs when the repaint method is called has become quite annoying! :mad: I have a Timer method coupled with the ActionListener to update the screen. The need for the update is because I move the targets by pixels so when the ActionListener is called, it changes the coordinates of the targets. Because pixels are small, the repaint method is called about 100 times per second. This is supposed to make the targets move seemlessly throughout the Applet; however, the applet blinks so bad that my eyes hurt! Looking at recent projects in my AP Comp Sci class, not one person has been able to avoid this problem, not even in the old C++ programs. If anyone has a solution to offer, it would most greatly be appreciated. Happy Programming!
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 72
Reputation: gusano79 is on a distinguished road 
Solved Threads: 4
gusano79 gusano79 is offline Offline
Junior Poster in Training

Re: Java Applet viewer blinks everytime the init method is used.

 
0
  #2
May 18th, 2004
Originally Posted by Radahl
... the constant blinking that occurs when the repaint method is called has become quite annoying! ...
Yes it is, especially if you're epileptic.

Quick explanation: When you call repaint, that ends up placing a call to update, which does a fillrect to clear the drawing area and then calls paint. To get rid of the clearing on each frame, you have to override the update method of your applet (or whatever class your drawing surface lives in) so it simply calls your paint method:

  1. public void update(Graphics g)
  2. {
  3. paint(g);
  4. }

This stops the flicker, but creates more work for you. If you don't clean up the previous frame, your targets will leave slimy trails everywhere. For moving objects, there's usually substantial overlap between frames, so you can draw the new object over most of the old one and only erase the part that's left over. If you look closely enough, you'll be able to see this happening, but it's nowhere near as noticeable as the flicker problem you're having.

If you want it really smooth, use a double buffer. Have a look at java.awt.Image; you can draw to an off-screen graphics context for each frame and zap it into the applet once you're finished. Then flicker doesn't matter because you'll never actually see the drawing operations happening--you only get the final image each frame.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC