Flicker-free Animation Using Java

Currently the most popular use of Java seems to be in building Applets. In this article Paul shows you not only how to make a applet, but how to make it look good.


Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Unome's picture

I understand the concept of double-buffering and have used it a bunch, but I've run into a problem that I just simply cannot solve. I'm creating an applet with a little Marine that has a machine gun. A mouse listener tracks your mouses location to move his arm with the cursor angle, and a click listener fires bullets. There is more too it but thats not important. My problem is, in order to rotate the image of both his arm... and the gun I had to use AffineTransform and set somethings with that.... the methods for affineTransform aren't carried over to offscreen images, so I can't rotate the arm if I draw to an offscreen. As you can see I'm kinda stuck between a rock and a hard place. I can either have my program function smoothly with an arm that stays still as bullets fly out of nowhere. Or I can have a flickering monster that works seamlessly underneath....

Is there any other way to stop flickering? Or is their a way to make AffineTransform work with offscreen images?

Please let me know if you can! I'd really appreciate the help. I can show you my code it you need it.

Thank you !

Ulhume's picture

I spent days trying to find this tiny little getToolkit().sync() function. Great tutorial and thanks again for your help !

Re: Flicker-free Animation Using Java

Anonymous's picture

X windows double buffers too. I came across this page when i ran into a JTable flickering like crazy when you scroll it, update it, whatever on windows. I had been developing the damn thing in FreeBSD the whole time, so i never saw the flicker. When i dropped it into a webpage and tested it on a windows box, all i saw was flicker.

Silly windows..

- Kevin

Re: Flicker-free Animation Using Java

Anonymous's picture


Kevin: How did you fix it? I'm running into a similar problem, although in an application, not an applet, and on OSX, not Windows, but any hints about getting rid of redraw flicker are desperately needed.


-- Morgan

Re: Flicker-free Animation Using Java

Anonymous's picture

In Mac OS X it appears java applets are flicker free. Perhaps because all windows are double buffered to begin with ( unless for some bizarre reason ). Try it. I'm not crazy. Is it just Mac OS X thats does this? Any other operating systems that don't require direct double buffering in java?

A similar issue

Ben's picture

Yeah, I'm having the exact same problem. I thought it was because of my Eclipse build, or that I'm running Vista or something, but yes. At school, I run Java on OS X and it's silky smooth. on Vista, ugly flickering monster with the exact same code.

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState