Eliminate flicker with dual buffering technology in Java

Source: Internet
Author: User

When writing a window program with a consistent change in Java, the usual approach is to overwrite the parent class's Paint (Graphics) method in the subclass and use the GUI function in the method to redraw the window. The window of a coherent transformation constantly calls the update (graphics) function, which automatically calls the paint (graphics) function. This will cause a flashing situation.

In order to solve this problem, double buffering technology can be applied. You can override the above procedure by overwriting the update (graphics) function, creating a graphic in memory that is the same size as the window, obtaining the graphics context (graphics) of the graphic, and then invoking the graphics context of the picture as an argument to paint (graphics) function (the GUI function in the paint (graphics) is drawn on the picture), and then the update (graphics) function calls the DrawImage function to draw the created graphic directly onto the window.

/** * Overwrite the Update method, intercept the default calling procedure */public void Update (Graphics g) {Image buffer = CreateImage (This.getwidth (), This.getheight () );//create graphics buffer Graphics Goff = Buffer.getgraphics ();//Gets the graphics context of the graphics buffer paint (goff);//Draw a drawing process with the paint method to plot the drawing buffer goff.dispose ();//Release Graphics context resource G.drawimage (buffer, 0, 0, this);//Draw the graphics buffer to the screen}

  

Eliminate flicker with dual buffering technology in Java

Related Article

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.