%@ Language=VBScript %>
´õºí ¹öÆÛ¸µÀº À̹ÌÁö¸¦ ȸ鿡 ¹Ù·Î ±×¸®´Â °ÍÀÌ ¾Æ´Ï¶ó, ¸Þ¸ð¸®(¹öÆÛ)¿¡ ¸ÕÀú ±×¸®°í ȸ鿡 ³ªÁß¿¡ ±×¸®´Â ¹æ¹ýÀÌ´Ù. ´õºí ¹öÆÛ¸µÀº ȸéÀÇ ±ôºýÀÓÀ» ÁÙÀ̰í, ÀÚ¿¬½º·¯¿î ¾Ö´Ï¸ÞÀ̼ÇÀ» À§Çؼ ¸¹ÀÌ »ç¿ëµÈ´Ù. ´õºí ¹öÆÛ¸µÀ» Çϱâ À§Çؼ´Â ´ÙÀ½°ú °°Àº ÀýÂ÷¸¦ °ÅÃÄ¾ß ÇÑ´Ù.
¿¹: 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);
}
}