Timer 小程序问题??????需要大家帮忙???
我想用Timer每秒动态显示 时间??编写程序后,却不能实现,大家帮忙解决一下?谢谢 代码如下:
import java.util.Timer;
import java.util.TimerTask;
import java.util.Calendar;
public class MyTimer
{
Timer timer;
MyTimer()
{
timer = new Timer();
timer.schedule(new TiTask(),1000);
}
class TiTask extends TimerTask
{
Calendar ca = Calendar.getInstance();
public void run()
{
System.out.println(ca.get(Calendar.YEAR)+"年"+ca.get(Calendar.MONTH)+"月"+ca.get(Calendar.DAY_OF_MONTH)+" "+ca.get(Calendar.HOUR_OF_DAY)+"时"+ca.get(Calendar.MINUTE)+"分"+ca.get(Calendar.SECOND)+"秒");
System.exit(0);
}
}
public static void main(String[] args)
{
MyTimer obj = new MyTimer();
}
}