package?cn.test;
成都創(chuàng)新互聯(lián)公司憑借在網(wǎng)站建設(shè)、網(wǎng)站推廣領(lǐng)域領(lǐng)先的技術(shù)能力和多年的行業(yè)經(jīng)驗,為客戶提供超值的營銷型網(wǎng)站建設(shè)服務(wù),我們始終認(rèn)為:好的營銷型網(wǎng)站就是好的業(yè)務(wù)員。我們已成功為企業(yè)單位、個人等客戶提供了網(wǎng)站建設(shè)、網(wǎng)站設(shè)計服務(wù),以良好的商業(yè)信譽,完善的服務(wù)及深厚的技術(shù)力量處于同行領(lǐng)先地位。
import?java.text.SimpleDateFormat;
import?java.util.Date;
import?java.util.Timer;
import?javax.swing.JFrame;
import?javax.swing.JTextField;
public?class?Time?extends?JFrame?{
private?JTextField?TimeBox?=?new?JTextField();
private?Timer?timer?=?new?Timer()?;
private?SimpleDateFormat?sdf?=?new?SimpleDateFormat("HH:mm:ss");
public?Time()?{
TimeBox.setBounds(0,?0,?100,?50);
add(TimeBox);
//方法1?定時器方法?
//????????TimerTask?task?=?new?TimerTask()?{
//????????????@Override
//????????????public?void?run()?{
//????????????????TimeBox.setText(sdf.format(new?Date()));
//????????????}
//????????};
//????????timer.schedule(task,?1000,1000)?;
//方法2?線程休眠方法?
Display?timedisplay?=?new?Display();
timedisplay.start()?;
}
private?class?Display?extends?Thread?{
SimpleDateFormat?sdf?=?new?SimpleDateFormat("HH:mm:ss");
public?Display()?{
System.out.println("display");
}
@Override
public?void?run(){
while(true){
System.out.println(?"Thread?is?running..."?);????
TimeBox.setText(sdf.format(new?Date()));
try?{
Thread.sleep(1000)?;
}?catch?(InterruptedException?e)?{
System.out.println("sleep?error!!");
e.printStackTrace();
}
}
}
}
public?static?void?main(String[]?args)?{
Time?t?=?new?Time()?;
t.setSize(300,?200)?;
t.setResizable(false)?;
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
t.setVisible(true)?;
}
}
private?Shape?rect;????????????//背景矩形
private?Font?font;????????????//設(shè)置字體
private?Date?date;????????????//現(xiàn)在的時間
private?Thread?time;????????//時間線程
private?CanvasPanel?canvas;
public?static?void?main(String[]?args)?{
new?TimerTest20140930();
}
public?TimerTest20140930(){
super("繪制文本");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,300);
rect?=?new?Rectangle2D.Double(10,10,200,100);
font?=?new?Font("宋體",Font.BOLD,16);
canvas=new?CanvasPanel();
add(canvas);
time?=?new?Thread(new?Runnable(){
public?void?run(){
while(true){
canvas.repaint();
try{
Thread.sleep(1000);
}catch(Exception?ex){
}
}
}
});
time.start();
setLocationRelativeTo(null);
setVisible(true);
}??
class?CanvasPanel?extends?Canvas?{
public?void?paint(Graphics?g){
super.paint(g);
Graphics2D?g2?=?(Graphics2D)?g;
g2.setColor(Color.BLACK);
g2.fill(rect);
g2.setColor(Color.BLUE);
g2.setFont(font);
g2.drawString("現(xiàn)在的時間是",?20,?30);
date?=?new?Date();
g2.drawString(String.format("%tr",?date),?50,?60);???????
}
}
html
head
title時鐘特效/title
script type="text/javascript"
function disptime(){
var today = new Date(); //獲得當(dāng)前時間
var hh = today.getHours(); //獲得小時、分鐘、秒
var mm = today.getMinutes();
var ss = today.getSeconds();
/*設(shè)置div的內(nèi)容為當(dāng)前時間*/
document.getElementById("myclock").innerHTML="h1現(xiàn)在是:"+hh+":"+mm+":"+ss+"h1";
document.getElementById("myClock1").value=hh+":"+mm+":"+ss;
/*
使用setTimeout在函數(shù)disptime()體內(nèi)再次調(diào)用setTimeout
設(shè)置定時器每隔1秒(1000毫秒),調(diào)用函數(shù)disptime()執(zhí)行,刷新時鐘顯示
*/
var myTime=setTimeout("disptime()",1000);
}
/script
/head
body onload="disptime()"
div id="myclock"/div
input type="text" id="myClock1" value=""/input
/body
/html