애플릿에서 4 개의 스레드를 사용하고 Runnable 인터페이스를 사용하여 모든 스레드를 필요한 위치로 이동하려고합니다.Java의 멀티 스레딩
내 애플릿에서 구름 이미지가 y 축에서 o에서 750으로 걷고 구름이 y 축에서 150에 오면 헬리콥터가 걷기 시작하고 헬리콥터가 350에 도달 할 때까지 걷고 나서이 스레드가 멈 춥니 다. 그리고 나서 헬리콥터가 200에 도달하면 사람의 이미지가 나오고 x 축으로 걸어갑니다. 5 초에서 10 밀리 초가 지나면 멈 춥니 다. 당신은 UI 스레드에서 자고 싶어 결코 모든
import java.applet.* ;
package com.pack;
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class HelicopterScene extends Applet {
Image a, b, c;
int i, j, h, p;
public void init() {
i = 20;
j = 750;
h = 0;
a = getImage(getCodeBase(), "HelicopterAttack.jpg");
b = getImage(getCodeBase(), "pppp.png");
c = getImage(getCodeBase(), "helicopter1.png");
}
public void paint(Graphics g) {
showStatus(" Helicopter Scene Applet is started.....");
g.drawImage(a, 0, 0, this);
if (i <= 750 && j >= 20) {
if (i >= 150) {
g.drawImage(c, h, 255, 150, 35, this);
h++;
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException w) {
}
}
g.drawImage(b, j, 120, 90, 70, this);
g.drawImage(b, i, 180, 120, 70, this);
i++;
j--;
repaint();
try {
Thread.sleep(10);
if (i == 750 && j == 20) {
p = h;
g.drawImage(c, p, 255, 150, 35, this);
h++;
repaint();
try {
Thread.sleep(20);
} catch (InterruptedException w) {
}
i = 20;
j = 750;
}
} catch (InterruptedException e) {
}
}
}
}
작동하지 않습니까? –
숙제 인 경우 질문에 적절한 태그를 추가하십시오. – Crozin