Applet 双缓冲技术

import java.applet.Applet;
import java.awt.Graphics;
import java.awt.HeadlessException;
import java.awt.Image;

import javax.swing.JApplet;

public class Test1 extends JApplet 
{
	private static final long serialVersionUID = 1L;

	private Image deitel;
	
	Graphics page;

	Image memPage;		
	
	String imgName=null;
	
	public void init() 
	{			
		deitel = getImage(getDocumentBase(), "ok.jpg");	
		
		memPage = createImage(1920, 1080);
		page = memPage.getGraphics();
	}
	
	public void paint(Graphics g) 
	{
		page.drawImage(deitel,0, 0, deitel.getWidth(this), deitel.getHeight(this), this);
		g.drawImage(memPage,0,0,this);
		repaint();
	}
	
	public Test1() throws HeadlessException 
	{
		super();
	}

}
注意:图片与该类存放到同一目录下,若不在同一目录下,则使用相对路径即可。

 

你可能感兴趣的:(java,swing)