- 论坛徽章:
- 0
|
程序如下:
import java.util.*;
import java.awt.*;
public class Clock extends java.applet.Applet implements Runnable
{
Thread clockThread;
public void run()
{
while (clockThread!=null)
{
repaint();
try
{
clockThread.sleep(1000);
}
catch (InterruptedException e)
{
System.out.println(e);
}
}
}
public void paint(Graphics g)
{
Date now = new Date();
g.drawString(now.getHours()+":"+now.getMinutes()+":"+now.getSeconds(),5,10);
}
public void stop()
{
clockThread.stop();
clockThread = null;
}
public static void main(String args[])
{
Thread clockThread;
//if (clockThread==null)
//{
clockThread = new Thread("Clock" ;
clockThread.start();
//}
}
}
编译如下:
E:\java>;javac Clock.java
Note: Clock.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details. |
|