ttyyiiee 荣誉会员 #1 2006-06-11 02:55 私信 引用 编辑 何必呢,还要用Applet编写的,不知楼主想实现什么?用javascript不就可以实现的吗"能够网络对时"不知具体指什么?没听过这种说法是不是和当前时间一样啊,并可以自己走动呢?
freeboy 风云元老 #2 2006-06-11 20:44 私信 引用 编辑 Quote:引用第1楼ttyyiiee于2006-06-11 02:55发表的“”:何必呢,还要用Applet编写的,不知楼主想实现什么?用javascript不就可以实现的吗"能够网络对时"不知具体指什么?没听过这种说法是不是和当前时间一样啊,并可以自己走动呢?老师要求要用Applet的,用Application也可以。网络对时不要也可以。
ttyyiiee 荣誉会员 #3 2006-06-12 00:27 私信 引用 编辑 试下这个呢!Copy codeimport 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>[ 此贴被beckey在2006-06-12 14:28重新编辑 ]
ttyyiiee 荣誉会员 #6 2006-06-25 23:11 私信 引用 编辑 第一个方法是线程的开始运行开始的方法,第二个就是一秒运行一次,第三个是得到当前时间,第四个用来停止线程的,要不要都没有关系.去看看线程不可以了,里面有讲的,记得我发了一片文章上面就是说这个里面的一些东西的,重点的吧,就是线程有关的那个看看.implements、线程[ 此贴被ttyyiiee在2006-06-25 23:19重新编辑 ]