글쓴이 :박성호 1999년 3월 23일 09:50:19
안녕하세요...
급한 문제가 있어서 질문 올립니다...
여러 고수님들의 조언 부탁합니다.
제가 만들려고 하는 것은 network 및 local상에서의
IO에서 진행상태에 대한 정보를 보기 위한
Progress나 animation을 보여줄려 합니다..
그런데 문제는 repaint()에 의한 paint() 호출이
실행이 안된다는 것입니다...
물론 animation이나 progressbar는 Runnable을 상속받아
Thread 처리를 했구요...
같은 현상이 발생해서 IO 역시 thread 처리를 해서
yield 및 priority를 낮췄는데 JDK 117에서는 역시
안되구 IE4.0에서는 실행이 되더군요...
해결하기 위해선 io와 progress를 동기화 시켜야하는지요...?
가령 io에서 일정 data를 읽은 후 progress thread를
notify 시키고 wait하며 또한 progress는 wait하여 notify를
기다리며 repaint후 io thread를 notify하고 wait하는식으로
해야하는지...
적절한 방법을 찾지못해 이렇게 해매고 있습니다.
다음은 소스입니다. 조언 부탁드립니다.
개발환경은 jdk1.1.7입니다.
------------------------------------------------------
// IO 호출 루틴 class
progress.showProgress( true);
io.start();
progress.showProgress( false);
// IO 수행 class =====================================
public void run(){
// Data Load하는 부분
}
public void start(){
thread = new Thread( this);
thread.setPriority( Thread.MIN_PRIORITY);
thread.yield();
thread.start();
}
=======================================================
public class ProgressPane extends Canvas implements Runnable{
Thread thread;
boolean suspended = true;
int pos;
public ProgressPane(){
thread = new Thread( this);
thread.start();
}
public void paint(Graphics g){
if(suspended) return;
int w= ( getSize().width * 10) / 100;
int h= getSize().height;
int x= ((getSize().width - w) * pos) / 100;
g.setColor(Color.blue);
g.fillRect(x, 5, w, h-10);
}
public void showProgress( boolean flag){
if( flag)
showProgress();
else
hideProgress();
}
public void showProgress(){
synchronized(this){
suspended = false;
notify();
}
}
public void hideProgress( ){
if(!suspended){
suspended = true;
thread.interrupt();
}
}
public void run(){
while(true){
synchronized(this){
try{
while( suspended){
wait();
}
}
catch(InterruptedException e){}
try{
int increament= 10;
pos= 0;
while (true){
repaint();
thread.sleep(150L);
pos= pos + increament;
if( ! ( (pos > 100) || (pos < 0)) ){
continue;
}
increament= -increament;
pos= pos + (2 * increament);
continue;
}
}
catch(InterruptedException e){}
}
}
}
}