想写个动画变化啊,
已经写了一个函数 setImg(int num);//能够把某个按钮的图片改成"img/pic"+num+".png";图片在资源里面,已经测试没问题,单独执行切换正常.
然后写了个loop
for(int i=0;i<9;i++){
setImg(i);
Thread.Sleep(200);//Thread.currentThread()效果一样..
}
然后能看到的只有最后一张图片...
运行完就突然卡了啊..似乎卡了9*200ms啊,然后才看到图片变换,不过是瞬间的了..所以就是最后一张...
那个高手帮忙解决一下啊...本人新手上路,感谢了啊!!T_T
已经写了一个函数 setImg(int num);//能够把某个按钮的图片改成"img/pic"+num+".png";图片在资源里面,已经测试没问题,单独执行切换正常.
然后写了个loop
for(int i=0;i<9;i++){
setImg(i);
Thread.Sleep(200);//Thread.currentThread()效果一样..
}
然后能看到的只有最后一张图片...
运行完就突然卡了啊..似乎卡了9*200ms啊,然后才看到图片变换,不过是瞬间的了..所以就是最后一张...
那个高手帮忙解决一下啊...本人新手上路,感谢了啊!!T_T
解决方案 »
- 求助高手指导:java从oracle 中读取blob字段转换成字符串后生成了各种字符
- 关于ObjectInputStream读写
- 着急!!!javax.el.PropertyNotFoundException: Property 'EmployeeID' not found on type
- <xsd:element saw-name:hello="world"/>如何解析?
- 求和问题
- 我想问下大家关于取mac地址的问题?
- 在java中像ActionListener这样的接口类(在java帮助文档里面有的)有哪些,举些常用的,说明用途,谢谢!!
- 请问高手:java中的数据流问题
- 请教请教,新人不懂啊
- 为什么不遍历就能够输出char类型的数组?
- Teacher(String n, String l, String capital)这里n和l都冒定义怎么可以这样写呢?
- 遍历修改
1000ms才是一秒啊.
Thread t = new Thread(){
public void run()
{
int i = 0;
while(true){
if(i >max)i = 0;//从头循环
setImg(i++);
Thread.Sleep(200);//Thread.currentThread()效果一样..
} }
public void run(){
for (int i=0;i<10;i++){
DisplayArray[0][0].setIMG(boxImg.getImg1(i));
try{
Thread.currentThread().sleep(200);
}catch(InterruptedException es){
}
}
}
算是独立了吧,但是还是不行啊
private BgImg boxImg;//一个菜单按钮激活
menuItem.addActionListener(
new ActionListener(){
public void actionPerformed(ActionEvent e){
Thread tt=new Thread(){
public void run(){
for (int i=0;i<10;i++){
test--;
if( test>=0){
DisplayArray[0][0].setBackground(Color.RED);
DisplayArray[0][0].setIMG(boxImg.getImg1(test));
}else if (test>=-7){
DisplayArray[0][0].setBackground(Color.RED);
DisplayArray[0][0].setIMG(boxImg.getImg2(-test));
if (test<-1){
DisplayArray[1][0].setBackground(Color.RED);
DisplayArray[1][0].setIMG(boxImg.getImg1(9+test+1));
}
}
try{
Thread.currentThread().sleep(500);
}catch(InterruptedException es){
}
}
}
};
tt.run();
}
}
);public class SquareBox extends JButton{
private static final long serialVersionUID = 3642375119924499879L;
public static int countColumn=0;
private int columnNum;
public SquareBox(ImageIcon img){
this.setIcon((Icon)img);
this.setBackground(Color.WHITE);
this.setBorder(null);
this.setSize(60, 60);
}
public void setColumn(int x){
columnNum=x;
}
public int getColumnNum(){
return columnNum;
}
public void setIMG(ImageIcon img){
this.setIcon((Icon)img);;
}
}package comp229.s40928497.connect4.interface_;
import javax.swing.ImageIcon;
public class BgImg {
private ImageIcon[] imageSet1;
private ImageIcon[] imageSet2;
BgImg(){
imageSet1=new ImageIcon[9];
for(int i=0;i<9;i++){
imageSet1[i]=new ImageIcon(getClass().getResource("/img/box"+i+".png"));
}
imageSet2=new ImageIcon[8];
for(int i=0;i<8;i++){
imageSet2[i]=new ImageIcon(getClass().getResource("/img/boxdown"+(i+1)+".png"));
}
}
public ImageIcon getImg1(int imgNum){
return imageSet1[imgNum];
}
public ImageIcon getImg2(int imgNum){
return imageSet2[imgNum];
}}
启动一个线程不要直接run