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(); } } }
Joburgess
相关分类