java,php,asp.net,linux,javascript,mysql,mssql,oracle,编程

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

转载请注明:http://www.pmjava.com/Article/ShowInfo.asp?ID=56609
*心得: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));
*/


import java.awt.*;
import java.awt.event.*;
import java.util.*;

public class WorldClock{
    Frame f
=new Frame("WorldClock");
    Label l1
=new Label();
    Label l2
=new Label();
    Label l3
=new Label();
    Label cl1
=new Label();
    Label cl2
=new Label();
    Label cl3
=new Label();
   
   
public WorldClock(){
       
        l1.setFont(
new Font("Arial",Font.BOLD,30));
        l2.setFont(
new Font("Arial",Font.BOLD,30));
        l3.setFont(
new Font("Arial",Font.BOLD,30));
        cl1.setFont(
new Font("Arial",Font.BOLD,30));
        cl2.setFont(
new Font("Arial",Font.BOLD,30));
        cl3.setFont(
new Font("Arial",Font.BOLD,30));
        cl1.setForeground(Color.red);
        cl2.setForeground(Color.red);       
        cl3.setForeground(Color.red);
       
        f.setLayout(
new GridLayout(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
=new clock(l1,cl1,tz1);
       
new Thread(c1).start();
       
        TimeZone tz2
=TimeZone.getTimeZone("Asia/Shanghai");
        clock c2
=new clock(l2,cl2,tz2);
       
new Thread(c2).start();
       
        TimeZone tz3
=TimeZone.getTimeZone("Europe/Rome");
        clock c3
=new clock(l3,cl3,tz3);
       
new Thread(c3).start();
       
        f.setLocation(
200,200);
        f.setVisible(
true);
        f.pack();
       
       
    }
   
public static void main(String[] args){
       
new WorldClock();
        String[] s
=TimeZone.getAvailableIDs();
       
int i=0;
       
while(++i<s.length){
            System.out.println (s[i]);
        }
    }
}

class clock implements Runnable{
   
private Label l;
   
private Label clk;
    TimeZone tz;
   
   
public clock(Label l,Label clk,TimeZone tz){
       
this.l=l;
       
this.clk=clk;
       
this.tz=tz;
    }
   
   
public void run(){
        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();
            }
           
        }
    }
}
                            

posted on 2009-06-10 21:41 rrong_m 阅读(247) 评论(0)  编辑  收藏

<2024年11月>
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

导航

统计

常用链接

随笔档案

文章分类

文章档案

java编程

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜