java循环播放_java程序!!求大神修改一下!想让动画循环播放

package luoye;

import java.applet.*;

import java.awt.*;

public class luoye extends Applet implements Runnable{

Image shu,ye1,ye2,ye3,ye4;

int x1 = 320,y1 = 300;

int x2 = 160,y2 = 295;

int x3 = 270,y3 = 320;

int x4 = 105,y4 = 310;

public void playsound(){

AudioClip audioClip=getAudioClip(getCodeBase(),"1324.wav");

audioClip.loop();

}

public void init(){

playsound();

setSize(700,400);

shu = getImage(getCodeBase(), "shu.jpg");

ye1 = getImage(getCodeBase(), "ye1.jpg");

ye2 = getImage(getCodeBase(), "ye2.jpg");

ye3 = getImage(getCodeBase(),"ye3.jpg");

ye4 = getImage(getCodeBase(),"ye4.jpg");

}

public void paint(Graphics g){

g.drawImage(shu, 0, 0, 500, 400, this);

g.drawImage(ye1, x1, y1, 20, 20, this);

g.drawImage(ye2, x2, y2, 20, 20, this);

g.drawImage(ye3, x3, y3, 20, 20, this);

g.drawImage(ye4, x4, y4, 20, 20, this);

}

public void start() {

Thread ye1 = new Thread(this, "ye1");

Thread ye2 = new Thread(this, "ye2");

Thread ye3 = new Thread(this,"ye3");

Thread ye4 = new Thread(this,"ye4");

ye1.start();

ye2.start();

ye3.start();

ye4.start();

}

public void run() {

boolean stop = false;

while (!stop) {

try {

Thread.sleep(100);

x1=x1-1;

y1=y1+5;

x2=x2-1;

y2=y2+5;

x3=x3-1;

y3=y3+5;

x4=x4-1;

y4=y4+5;

String threadName = Thread.currentThread().getName();

if (threadName.equals("ye1")) {

if (y1 == 400) {

//stop = true;

x1 = 320;

y1 = 300;

Thread.sleep(1000);

}

} else if (threadName.equals("ye2")) {

if (y2 == 400) {

//stop = true;

x2 = 170;

y2 = 295;

Thread.sleep(1000);

}

} else if(threadName.equals("ye3")){

if (y3 == 400) {

//stop = true;

x3 = 270;

y3 = 320;

Thread.sleep(1000);

}

}

else if(threadName.equals("ye4")){

if (y4 == 400) {

//stop = true;

x4 = 105;

y4 = 310;

Thread.sleep(1000);

}

}

}

catch(Exception e){}

repaint();

}

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值