java多线程世界时钟_多线程的世界时钟,显示巴黎,罗马,上海时间, AWT界面

*心得:TimeZone tz1=TimeZone.getTimeZone("Europe/Paris");

*      Calendar cld=Calendar.getInstance(tz);

*      clk.setText(cld.get(Calendar.HOUR_OF_DAY)+":"+cld.get(Calendar.MINUTE)+":"+cld.get(Calendar.SECOND));*/importjava.awt.*;importjava.awt.event.*;importjava.util.*;publicclassWorldClock{

Frame f=newFrame("WorldClock");

Label l1=newLabel();

Label l2=newLabel();

Label l3=newLabel();

Label cl1=newLabel();

Label cl2=newLabel();

Label cl3=newLabel();publicWorldClock(){

l1.setFont(newFont("Arial",Font.BOLD,30));

l2.setFont(newFont("Arial",Font.BOLD,30));

l3.setFont(newFont("Arial",Font.BOLD,30));

cl1.setFont(newFont("Arial",Font.BOLD,30));

cl2.setFont(newFont("Arial",Font.BOLD,30));

cl3.setFont(newFont("Arial",Font.BOLD,30));

cl1.setForeground(Color.red);

cl2.setForeground(Color.red);

cl3.setForeground(Color.red);

f.setLayout(newGridLayout(2,3));

f.add(l1);

f.add(l2);

f.add(l3);

f.add(cl1);

f.add(cl2);

f.add(cl3);

TimeZone tz1=TimeZone.getTimeZone("Europe/Paris");

clock c1=newclock(l1,cl1,tz1);newThread(c1).start();

TimeZone tz2=TimeZone.getTimeZone("Asia/Shanghai");

clock c2=newclock(l2,cl2,tz2);newThread(c2).start();

TimeZone tz3=TimeZone.getTimeZone("Europe/Rome");

clock c3=newclock(l3,cl3,tz3);newThread(c3).start();

f.setLocation(200,200);

f.setVisible(true);

f.pack();

}publicstaticvoidmain(String[] args){newWorldClock();

String[] s=TimeZone.getAvailableIDs();inti=0;while(++i

System.out.println (s[i]);

}

}

}classclockimplementsRunnable{privateLabel l;privateLabel clk;

TimeZone tz;publicclock(Label l,Label clk,TimeZone tz){this.l=l;this.clk=clk;this.tz=tz;

}publicvoidrun(){

l.setText(tz.getID());while(true){

Calendar cld=Calendar.getInstance(tz);

clk.setText(cld.get(Calendar.HOUR_OF_DAY)+":"+cld.get(Calendar.MINUTE)+":"+cld.get(Calendar.SECOND));try{

Thread.sleep(1000);

}catch(Exception e){

e.printStackTrace();

}

}

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值