该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
public void run() {
while(T1.isAlive()==true){
try {Thread.sleep(FrameRate);} catch (InterruptedException e) {}
if(this.NowIndex
{++this.NowIndex;}
else{this.NowIndex=0;}
}
}
这是一组图片的线程
NowIndex代表这组线程需要读取的那张图片的索引
每个Unit附带一个名为ImgUnitGroup的类
每个ImgUnitGroup类有12个图片组
每个图片组有Name属性,ImgUnitGroup类有一个寻找方法 根据12个元素的Name寻找到对应图片组 每个图片组有getNowImage来返回目前索引所对应的图片:
public BufferedImage getNowImage() {
return(ImgGroup.get(NowIndex));
}
每个图片组有这样一个方法启动线程(初始化时调用该方法)来实现动画图片更换的效果:
public void StartFrame(){
if(T1.isAlive()==false)
this.T1.start();
}
这是图片组的初始化方法:
public FAImageGroup(String Name,String Catalog,String Starting,Enum.ImageType Type) throws IOException{
this.GroupName=Name; //改图片组名称改为Name
String Str1 = "";
Str1=Catalog+Starting+"-"+"0"+".gif"; //读取图片
File f=new File(Str1);
if(f.exists()){
int n=0;
while(f.exists()){ //从这里开始读取文件夹中所有图片
ImgGroup.add(ImageIO.read(new File(Str1)));
n++;
Str1=Catalog+Starting+"-"+n+".gif";
f=new File(Str1);
}
this.Size=this.ImgGroup.size(); //设置图片组大小
}
}
图片刷新线程
public void run() {
while(true){
try {
Thread.sleep(this.RefreshRate);this.repaint();
} catch (InterruptedException e) {System.out.println("失败");
} }
}
重写的update
public void update(Graphics scr){
if(image==null){
image=(BufferedImage) createImage(this.getSize().width,this.getSize().height);
imgb=image.getGraphics();
}
paint(imgb);
scr.drawImage(image, 0, 0, this);
paint(scr);
}
重写的paint
public void paint(Graphics Gra1){
//建立临时缓冲图片
image=new BufferedImage(1000,600,BufferedImage.TYPE_3BYTE_BGR);
imgb=image.getGraphics();
int n=0;
while(n
imgb.drawImage(AllUnit.getAllUit().get(n).getNowImage(), AllUnit.getAllUit().get(n).getPosition().x, 600-AllUnit.getAllUit().get(n).getPosition().y, this);
n++;
System.out.println(n);
} //输出到屏幕
Gra1.drawImage(image, 0, 0, this);
}
求教