
求帮忙修改一下java动画
package luoye;
import java.applet.*;
import java.awt.*;
public class luoye extends Applet{
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);
try{
Thread.sleep(90);
x1=x1-1;
y1=y1+5;
x2=x2-1;
y2=y2+5;
x3=x3-1;
y3=y3+5;
x4=x4-1;
y4=y4+5;
if(y1 == 400){
x1 = 320;
y1 = 300;
Thread.sleep(1000);}
if(y2 == 400){
x2 = 170;
y2 = 295;
Thread.sleep(1000);}
if(y3 == 400){
x3 = 270;
y3 = 320;
Thread.sleep(1000);}
if(y4 == 400){
x4 = 105;
y4 = 310;
Thread.sleep(500);}}
catch(Exception e){}
repaint();
}
} 展开
package luoye;
import java.applet.*;
import java.awt.*;
public class luoye extends Applet{
public luoye() {
}
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(),"1.png");
audioClip.loop();
}
public void init(){
//playsound();
setSize(700,400);
shu = getImage(getCodeBase(), "1.png");
ye1 = getImage(getCodeBase(), "礼物.png");
ye2 = getImage(getCodeBase(), "1.png");
ye3 = getImage(getCodeBase(),"礼物.png");
ye4 = getImage(getCodeBase(),"1.png");
}
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);
try{
Thread.sleep(90);
x1=x1-1;
y1=y1+5;
x2=x2-1;
y2=y2+5;
x3=x3-1;
y3=y3+5;
x4=x4-1;
y4=y4+5;
if(y1 == 400){
x1 = 320;
y1 = 300;
//Thread.sleep(1000);
}
if(y2 == 400){
x2 = 170;
y2 = 295;
//Thread.sleep(1000);
}
if(y3 == 400){
x3 = 270;
y3 = 320;
//Thread.sleep(1000);
}
if(y4 == 400){
x4 = 105;
y4 = 310;
//Thread.sleep(500);
}
}
catch(Exception e){}
repaint();
}
}
虽然我没有看懂你的代码
但是有图有真相
效果图
如果你先加快你所谓的树叶的下降速度
try{
Thread.sleep(90);
这里的Thread.sleep(90);可以改成Thread.sleep(45);
2016-07-12 · 百度知道合伙人官方认证企业
