±Û¾´ÀÌ :avenger 1999³â 6¿ù 15ÀÏ 13:34:47
In Reply to: threadÀε¥ errorÁ» Àâ¾ÆÁÖ¼¼¿ä ³Ñ ¸¹¾Æ¿ä^^ posted by ³²ÇýÁø on 1999³â 6¿ù 15ÀÏ 10:49:43:
Á¶±Ý °íÃĺôµ¥ ¾Æ·¡¿Í °°ÀÌ Çϸé Àß µÉ°Ì´Ï´Ù.
¿½ÉÈ÷ Çϼ¼¿ä.
import java.applet.*;
import java.awt.*;
public class banner extends Applet implements Runnable
{
String msg;
int x, y;
int hStep;
int msgWidth;
Thread myThread;
public void init() {
msg="¾È³çÇϼ¼¿ä?";
hStep=3;
Font f=new Font("°íµñ",Font.BOLD, 20);
setFont(f);
FontMetrics fm=getFontMetrics(getFont());
msgWidth=fm.stringWidth(msg);
x=getSize().width;
y=getSize().height/2;
}
public void start()
{
myThread=new Thread(this);
myThread.start();
}
public void run()
{
while(myThread != null) {
repaint();
if(x>0-msgWidth)
x=x-hStep;
else
x=getSize().width;
try{
myThread.sleep(80);
}catch(InterruptedException e) {
e.printStackTrace();
}
}
}
public void paint(Graphics g)
{
g.drawString(msg,x, y);
}
public void stop()
{
myThread.stop();
}
}