±Û¾´ÀÌ :¹Ú¼ºÈ£ 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){}
}
}
}
}