📄 animotor.java
字号:
import java.applet.*;
import java.awt.*;
import java.util.Vector ;
public class Animotor extends Applet implements Runnable
{
private Vector images=new Vector();
private int imgCount;
private int currentImg=0;
private Thread thisThread;
private int meWidth,meHeight;
private Image imgoffScreen;
public void init()
{
imgCount=Integer.parseInt(getParameter("ImgCount"));
meWidth=getSize().width ;
meHeight=getSize().height ;
for(int i=1;i<=imgCount;i++)
{
images.addElement(getImage(getCodeBase(),"img/img" +i+".jpg"));
}
imgoffScreen=createImage(getSize().width,getSize().height);
}
public void paint(Graphics g)
{
g.setColor(Color.white);
g.fillRect(0,0,meWidth,meHeight);
g.drawImage((Image)images.elementAt(currentImg++),0,0,this);
currentImg %=imgCount;
}
public void start()
{
thisThread=new Thread(this);
thisThread.start ();
}
public void stop()
{
thisThread.stop();
}
public void run()
{
while(true)
{
repaint();
try
{
Thread.sleep(100);
}
catch(Exception e){}
}
}
//下面使用了双缓冲技术,如果不使用双缓冲
//即使从内存中读取图形依然还会闪烁
public void update(Graphics g)
{
Graphics offg=imgoffScreen.getGraphics();
offg.setColor(getBackground());
offg.fillRect(0,0,getSize().width,getSize().height);
offg.setColor(g.getColor());
paint(offg);
g.drawImage(imgoffScreen,0,0,this);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -