import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class Clock
{
NTJFrame frame = new NTJFrame("Clock");
Drawing drawing = new Drawing();
TimeKeeper time = new TimeKeeper();
int hours=0, minutes=0, seconds=0;
public Clock()
{
frame.getContentPane().add(drawing,"Center");
frame.setVisible(true);
time.start();
}
public static void main (String[] args)
{
new Clock();
}
class Drawing extends JComponent
{
public Drawing()
{
repaint();
}
public void paint(Graphics g)
{
g.drawString(hours + ":" + minutes + ":" + seconds, 100,100);
}
}
class TimeKeeper extends Thread
{
public void run()
{
try
{
while (true)
{
sleep(1000);
seconds++;
if (seconds > 59)
{
seconds = 0;
minutes++;
if (minutes > 59)
{
minutes = 0;
hours++;
}
}
drawing.repaint();
}
}
catch (InterruptedException e)
{
}
}
}
}
|