Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize double caching in Java

Shulou Source: shulou.com Published: 2022-06-02 02:39:35 09月26日 Update

Editor to share with you how to achieve double cache Java, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Import java.awt.*;import java.applet.*;public class HelloWorld extends Applet {imgBuf=createImage (getSize (). Width,getSize (). Height); gBuf=imgBuf.getGraphics (); gBuf.setColor (Color.black); gBuf.fillRect (0Color.white). Width,getSize (). Height); gBuf.setColor (Color.white); gBuf.drawLine (0Color.white); gBuf.drawLine (). Width-1,10); gBuf.drawLine (0min30) GBuf.drawLine (0mai 50) getSize (). Width-1,50); gBuf.drawLine (0Mei 70 getSize (). Width-1,70); gBuf.drawLine (0Mei 90 getSize (). Width-1,90); gBuf.drawLine (0mai 110 getSize (). Width-1110); gBuf.drawLine (0Metro 130 getSize (). Width-1130); gBuf.setColor (Color.red); gBuf.drawRect (0pr 0pr getSize (). Width-1,getSize (). Height-1);} public void start () {if (lithread==null) {lithread=new Thread (); lithread.start () }} public void stop () {lithread=null;} public void paint (Graphics g) {g.drawImage (imgBuf,0,0,this); gBuf.setColor (Color.black); gBuf.fillRect (0meme) getSize (). Width,getSize () .height); gBuf.setColor (Color.white); gBuf.drawLine (0meme 10pint getSize (). Width-1,10); gBuf.drawLine (0meme30pint getSize (). Width-1,30); gBuf.drawLine (0mai 50pint getSize (). Width-1,50); gBuf.drawLine (0Min 70pint getSize (). Width-1,70) GBuf.drawLine (0min90 gBuf.drawLine getSize (). Width-1,90); gBuf.drawLine (0meme 110 getSize (). Width-1110); gBuf.drawLine (0mai 130 minegetSize (). Width-1130); gBuf.setColor (Color.green); gBuf.drawRect (50comm 50lim 200lim 100lim); try {lithread.sleep (1000);} catch (InterruptedException e) {} ihammer; repaint ();} public void update (Graphics g) {paint (g);}}

Dual cache technology:

The root cause of image flicker is that when one image needs to spend the next one, the screen is cleared with the background color first, and then the next one is drawn, so people can see the background color flicker.

When an image is displayed, the next image to be displayed has been written in memory, so when the next image is needed, the display area can be unique from the memory directly through the function, because the reading speed from the memory is very fast. So you can't see the flicker.

These are all the contents of the article "how to achieve double caching in Java". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Image cache memory article content background unique one-time not much people functions reasons most screen fast technology time more fundamental knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei MariaDB MySQL Shulou Technology Redmi