글쓴이 :최효정 1998년 6월 29일 16:40:22
In Reply to: 이 애플릿의 문제점이 무엇인지.. posted by 최효정 on 1998년 6월 29일 15:10:53:
코드를 다음과 같이 수정했더니 해결이 됐는데..
paint메소드에서 왜 배열을 인식하지 못할까....
인덱스를 못알아먹어서 그러는지.. 잘 모르겠네요...
import java.awt.*;
import java.applet.*;
import java.lang.*;
public class TestLoadimage extends java.applet.Applet implements Runnable {
int imgidx = 0;
Image imgs[] = new Image[10];
Image currentimg;
Thread mythread;
public void run() {
for(int i=0, j=1; i<10; i++, j++) imgs[i] = getImage(getCodeBase(), "t" + j + ".gif");
while ( imgidx < 10) {
currentimg = imgs[imgidx];
repaint();
try { Thread.sleep(1000);
} catch(InterruptedException e) {}
imgidx++;
}
}
public void start() {
if(mythread == null) {
mythread = new Thread(this);
mythread.start();
}
}
public void stop() {
if(mythread != null) {
mythread.stop();
mythread = null;
}
}
public void paint(Graphics g) {
g.drawImage(currentimg, 10, 10, this);
}
}