您的位置:首页 > 编程语言 > Java开发

JAVA电子时钟

2015-06-25 21:03 375 查看
import java.awt.*;
import java.util.*;

import javax.swing.*;
public class HyClock extends JFrame implements Runnable{
public static JLabel tm;
public static  HyClock hytime;
public void run()
{while(true){

Calendar c=Calendar.getInstance();
String nowtime=c.get(Calendar.HOUR_OF_DAY)+":"+c.get(Calendar.MINUTE)+":"+c.get(Calendar.SECOND);

tm.setText(nowtime);

try {
Thread.sleep(1000);
} catch (InterruptedException e) {
}

}
}
public static void main(String[] agrs)
{
hytime=new HyClock();
hytime.setLayout(new FlowLayout());
tm=new JLabel();
tm.setFont(new Font("宋体",1,40));
tm.setForeground(Color.RED);
hytime.add(tm);
hytime.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
hytime.setSize(300,100);
hytime.setVisible(true);
hytime.setLocation(400,400);
Thread t=new Thread(hytime);
t.start();

}
}

效果图
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: