import java.awt.*; import java.applet.*; import java.util.*; public class NaytaAika extends Applet implements Runnable { Thread AikaSaie = null; Font fontti = new Font("TimesRoman", Font.BOLD, 18); FontMetrics fontinMitat; String PaivaysAika; Date PaivaysAikaNyt; int x, y; public void init() { y = size().height/2; } public void start() { if (AikaSaie == null) { AikaSaie = new Thread(this); AikaSaie.start(); } } public void run() { while (true) { PaivaysAikaNyt = new Date(); repaint(); try { AikaSaie.sleep(500); } catch (InterruptedException e) { } } } public void paint(Graphics g) { g.setFont(fontti); fontinMitat = g.getFontMetrics(); PaivaysAika = PaivaysAikaNyt.toString(); x = (size().width - fontinMitat.stringWidth(PaivaysAika)) / 2; g.drawString(PaivaysAika, x, y); } }