*心得: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();
}
}
}
}