showimage_1.java

来自「主要是对于JAVA的编程的基本语言 希望能够帮得上你。」· Java 代码 · 共 68 行

JAVA
68
字号
package applet;

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

/*
 * 演示双缓冲技术,防止图像抖动
 */

public class ShowImage_1 extends Applet implements Runnable{
	Image offImage;
	Graphics offGraphics;
	Image image;
	Thread thread;
	boolean m_bRunning;
	int iPosY;
	
	public void init(){
		image=this.getImage(this.getCodeBase(),"applet/bird.jpg");		
	}
	
	public void start(){
		m_bRunning=true;
		thread=new Thread(this);
		thread.start();
	}
	
	public void stop(){
		m_bRunning=false;
	}
	
	public void update(Graphics g){
		paint(g);
	}
	
	public void paint(Graphics g){	
		offImage = createImage(this.getWidth(), this.getHeight());		
		offGraphics = offImage.getGraphics();
		offGraphics.setColor( getBackground() );
		offGraphics.fillRect(0, 0, this.getWidth(), this.getHeight());		
		offGraphics.drawImage(image,0,0,this.getWidth(),this.getHeight(),this);	
		offGraphics.setColor(Color.RED);
		offGraphics.fillArc(80, iPosY, 50,50, 0, 360);
		
		g.drawImage(offImage,0,0,this);
		
	}

	public void run()  {
		while(m_bRunning){
			if(iPosY<this.getHeight()){
				iPosY++;
			}else{
				iPosY=-50;
			}
				
			repaint();
			try {
				Thread.sleep(50);
			} catch (InterruptedException e) {			
				e.printStackTrace();				
			}
		}		
	}	
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?