Java swing repainting and dual-Buffer Optimization

Source: Internet
Author: User

Java swingRepainting and dual-Buffer Optimization

 

Cause: I want to write a question in the past two days.21Point game, when using the formJframe, Flash is serious. After special processing, it will be slightly better.AWTInsideFrame, No flashes after dual buffering.

 

Here we will discuss the painting problem in swing. There is no update () in the painting process in swing. By default, it is double buffering, but I don't know why it will flash. OnProgramIn the paint method, a dual-buffer front-and-backend alternate mechanism is written, which can be transient. Finally, a slightly better solution is to draw P1 at the front end and P2 at the back end, in the next cycle, the front-end draws P2, the back-end draws P3, and so on, so that the CPU will not be too tight, and the flickering phenomenon will be greatly improved.

 

The Drawing Mechanism of swing and AWT is very different. After switching to AWT, it is not a flash, so it is really depressing!

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.