📄 showimage_1.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -