<%@ Language=VBScript %> ÃÖÁ¾¸í´ÔÀÇ ÀÚ¹Ù°­Á - ´õºí ¹öÆÛ¸µ

´õºí ¹öÆÛ¸µ

- ÃÖÁ¾¸í

´õºí ¹öÆÛ¸µÀº À̹ÌÁö¸¦ È­¸é¿¡ ¹Ù·Î ±×¸®´Â °ÍÀÌ ¾Æ´Ï¶ó, ¸Þ¸ð¸®(¹öÆÛ)¿¡ ¸ÕÀú ±×¸®°í È­¸é¿¡ ³ªÁß¿¡ ±×¸®´Â ¹æ¹ýÀÌ´Ù. ´õºí ¹öÆÛ¸µÀº È­¸éÀÇ ±ôºýÀÓÀ» ÁÙÀ̰í, ÀÚ¿¬½º·¯¿î ¾Ö´Ï¸ÞÀ̼ÇÀ» À§Çؼ­ ¸¹ÀÌ »ç¿ëµÈ´Ù. ´õºí ¹öÆÛ¸µÀ» Çϱâ À§Çؼ­´Â ´ÙÀ½°ú °°Àº ÀýÂ÷¸¦ °ÅÃÄ¾ß ÇÑ´Ù.

  1. Image °´Ã¼¸¦ ¸¸µé¾î¼­ À̰÷¿¡ ±×¸²À» ±×¸°´Ù.
  2. update() ÇÔ¼ö´Â ¿À¹ö¶óÀ̵åÇØ¼­ paint() ÇÔ¼ö¸¦ È£ÃâÇϵµ·ÏÇÑ´Ù.
  3. paint() ÇÔ¼ö¿¡¼­´Â 1¹ø¿¡¼­ »ý¼ºÇÑ À̹ÌÁö¸¦ ±×¸°´Ù.
¿¹: Clock.java
import java.awt.*; 
import java.awt.image.*; 
import java.applet.*; 
import java.util.*; 
 
public class Clock extends Applet implements Runnable { 
        Date     day; 
        Thread   runner; 
        Image    img; 
        Graphics gc; 
        Font     font; 
        int      w, h, d; 
        boolean  stop = false;
 
        public void start() { 
                day = new Date(); 
                font = new Font("TimesRoman", Font.BOLD, 24); 
                FontMetrics metrics = getFontMetrics(font); 
                d = metrics.getDescent(); 
                w = metrics.stringWidth(day.toString())+10;
                h = metrics.getHeight()+10;

                img = createImage(w , h);
                gc = img.getGraphics(); 
                gc.setFont(font); 
                runner = new Thread(this); 
                runner.start(); 
        } 
 
        public void stop() {
                if(runner != null) {
                        stop = true;
                        runner = null;
                }
        }
 
        public void run() { 
                while(!stop) { 
                        day = new Date(); 
                        gc.setColor(Color.lightGray); 
                        gc.fillRect(0, 0, w + 10, h+10); 
                        gc.setColor(Color.black); 
                        gc.drawString(day.toString(),5, h -d); 
                        repaint(); 
                        try { 
                                Thread.sleep(1000); 
                        } catch(Exception ex) { 
                                System.out.println("Exception:" + ex.toString()); 
                        } 
                } 
        } 
 
        public void update(Graphics g) { 
                paint(g); 
        } 
 
        public void paint(Graphics g) { 
                g.drawImage(img, 10, 50, this); 
        } 
}