引用第1楼ttyyiiee于2006-06-11 02:55发表的“”:何必呢,还要用Applet编写的,不知楼主想实现什么?用javascript不就可以实现的吗"能够网络对时"不知具体指什么?没听过这种说法是不是和当前时间一样啊,并可以自己走动呢?
import java.awt.Graphics;import javax.swing.*;import java.util.Calendar;public class Clock extends JApplet implements Runnable{ Thread clockThread; public void start(){ if(clockThread==null){ clockThread=new Thread(this,"Clock"); clockThread.start(); } } public void run(){ while(clockThread!=null){ repaint(); try{ clockThread.sleep(1000); }catch(InterruptedException e){ } } } public void paint( Graphics g) { Calendar calendar = Calendar.getInstance(); long a=calendar.getTimeInMillis(); calendar.setTimeInMillis(a); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH) + 1; int day = calendar.get(Calendar.DAY_OF_MONTH); int hour = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); int second = calendar.get(Calendar.SECOND); String time=""; time=year+"年"+month+"月"+day+"日"+" "+hour+":"+minute+":"+second; super.paint(g); g.drawString(time,25,25); } public void stop(){ clockThread.stop(); clockThread=null; }}<html><applet code = "Clock.class" width = "400" height = "300" /></html> </html>