// Use a double buffer //USEDOUBLEBUFFERING.JAVA
Import java.awt. *; import java.applet. *;
Public Class Used Buffering Extends Applet Implements Runnable {Int x, Y, Movex, Movey, Width, Height; Thread NewThread; Graphics Drawoffscreen;
Public void init () {x = 0; // x coordinate y = 0; // Y coordinate MOVEX = 2; // x axis displacement Movey = 3; // Y axis displacement width = getSize (). width; // Applet's width = getSize (). Height; // applet's height OFFSCREEN = CREATEIMAGE (Width, Height); // Establish a secondary picture drawoffscreen = offscreen.getgraphics (); // Get the drawing class of the second screen}
Public void start () {newthread = new thread (this); // Establish a new thread newthread.Start ();
Public void stop () {newthread = null; // Set the thread empty}
Public void Paint (GRAPHICS G) {if (Width! = getSize (). width || Height! = getSize (). Height) {// If the applet size changes, re-generate the second screen width = getSize (). width; height = getSize (). Height; offscreen = createImage (width, height); drawoffscreen = offscreen.getgraphics ();} // Remove the second screen (ie, draw a rectangle with the same size as the applet) DrawoffScreen.setColor Color.Black); DrawoffScreen.FillRect (0, 0, width, height); // Draw solid park on the second screen (Representing the ball) DrawoffScreen.SetColor (Color.White); DrawoffScreen.Filloval (x, y, 30 , 30); // Post the secondary picture to the main screen G. DrawImage (Offscreen, 0, 0, this); // g.SetColor (color.white); // g.Filloval (x, y, 30, 30);
Public void update (graphics g) {// update function only calls the Paint () function instead of the clearance, then call Paint (g);}