桌面动态时钟编程代码(动态时钟图标)
求用java语言设计一个动态时钟,每秒刷新一次
package com.kaylves;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Clock {
public static void main(String[] args) throws InterruptedException {
JFrame f = new JFrame();
Timer timer = new Timer();
Thread th=new Thread(timer);
th.start();
JLabel time = new JLabel();
f.add(time);
f.setVisible(true);
f.pack();
while(true){
time.setText(timer.getCurrentTime());
}
}
}
class Timer implements Runnable {
private String currentTime;
public String getCurrentTime() {
Date d = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
currentTime = sdf.format(d);
return currentTime;
}
public void run() {
try {
Thread.sleep(1000);
getCurrentTime();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
完成给分
电脑桌面罗盘时钟源代码怎么写
import java.awt.*;
导入Java.awt.event.*;
import javax.swing.*;
import java.lang.*;
import java.util.*;
publicclassrunabletestextendsjframeimplementsrunnable {
JPanel pnlMain; //定义变量
Jlabel Lbl时间; //定义变量
thread thd时间; //定义变量
日期数据显示
PHP怎么实现动态时钟
脚本说明:
第一步:把如下代码加入body区域中:
script language="JavaScript"
function showMilitaryTime()
{
if (document.form.showMilitary[0].checked)
{
return true;
}
return false;
}
function showTheHours(theHour)
{
if (showMilitaryTime() || (theHour 0 theHour 13))
{
if (theHour == "0") theHour = 12;
return (theHour);
}
if (theHour == 0)
{
return (12);
}
return (theHour-12);
}
function showZeroFilled(inValue)
{
if (inValue 9)
{
return "" + inValue;
}
return "0" + inValue;
}
function showAmPm()
{
if (showMilitaryTime())
{
return ("");
}
if (now.getHours() 12)
{
return (" am");
}
return (" pm");
}
function showTheTime()
{
now = new Date
document.form.showTime.value = showTheHours(now.getHours()) + ":" + showZeroFilled(now.getMinutes()) + ":" + showZeroFilled(now.getSeconds()) + showAmPm()
setTimeout("showTheTime()",1000)
}
/script
FORM name=formINPUT name=showTime size=11
PINPUT CHECKED name=showMilitary type=radioMilitary TimeBRINPUT
name=showMilitary type=radio Unchecked 12 Hour Time /FORM
第二步:把body区域中的内容改为:
body bgcolor="#fef4d9" onload=showTheTime()
因为已经定义了函数了,也可以掉用
C语言模拟动态时钟程序
#include "stdio.h"
#include "dos.h"
//#include windows.h
#include time.h
#define S2M_M2H 60
struct N
{
int hour;
int minute;
int second;
} mytime = {0,0,0};
int main()
{
time_t rt;
struct tm *t;
time ( rt );
t = localtime ( rt );
mytime.hour=t-tm_hour;
mytime.minute = t-tm_min;
mytime.second = t-tm_sec;
//1楼答得不错,你不会自己合直来么,我帮你合起来了
//以后我白天不能上网,晚上来答一两个就玩去了,这题如果可行,就采纳1楼的,我没功劳
for(; ; mytime.second++)
{
if(mytime.second==S2M_M2H)
{
mytime.minute++;
mytime.second=0;
if(mytime.minute==S2M_M2H)
{
mytime.hour++;
mytime.minute=0;
}
}
{
printf("\b\b\b\b\b\b\b\b%2d:%02d:%02d",mytime.hour,mytime.minute,mytime.second);
delay(1000);
}
}
return 0;
}
谁能帮我用c语言编写桌面钟表啊!
#includemath.h
#includedos.h
#includegraphics.h
#define CENTERX 320 /*表盘中心位置*/
#define CENTERY 175
#define CLICK 100 /*喀嗒声频率*/
#define CLICKDELAY 30 /*喀嗒声延时*/
#define HEBEEP 10000 /*高声频率*/
#define LOWBEEP 500 /*低声频率*/
#define BEEPDELAY 200 /*报时声延时*/
/*表盘刻度形状*/
int Mrk_1[8]={-5,-160,5,-160,5,-130,-5,-130, };
int Mrk_2[8]={-5,-160,5,-160,2,-130,-2-130, };
/*时针形状*/
int HourHand[8]={-3,-100,3,-120,4, 10,-4,10};
/*分针形状*/
int MiHand[8]={-3,-120,3,-120,4, 10,-4,10};
/*秒针形状*/
int SecHand[8]={-2,-150,2,-150,3, 10,-3,10};
/*发出喀嗒声*/
void Click()
{
sound(CLICK);
delay(CLICKDELAY);
nosound();
}
/*高声报时*/
void HighBeep()
{
sound(HEBEEP);
delay(BEEPDELAY);
nosound;
}
/*低声报时*/
void LowBeep()
{
sound(LOWBEEP);
}
/*按任意角度画多边形*/
void DrawPoly(int *data,int angle,int color)
{
int usedata[8];
float sinang,cosang;
int i;
sinang=sin((float)angle/180*3.14);
cosang=cos((float)angle/180*3.14);
for(i=0;i8;i+=2)
{
usedata[i] =CENTERX+ cosang*data[i]-sinang*data[i+1]+.5;
usedata[i+1]=CENTERY+sinang*data[i]+cosang*data[i+1]+.5;
}
setfillstyle(SOLID_FILL,color);
fillpoly(4,usedata);
}
/*画表盘*/
void DrawClock(struct time *cutime)
{
int ang;
float hourrate,minrate,secrate;
setbkcolor(BLUE);
cleardevice();
setcolor(WHITE);
/* 画刻度*/
for(ang=0;ang360;ang+=90)
{
DrawPoly(Mrk_1,ang,WHITE);
DrawPoly(Mrk_2,ang+30,WHITE);
DrawPoly(Mrk_2,ang+60,WHITE);
}
secrate=(float)cutime-ti_sec/60;
minrate=((float)cutime-ti_min+secrate)/60;
hourrate=(((float)cutime-ti_hour/12)+minrate)/12;
ang=hourrate*360;
DrawPoly(HourHand,ang,YELLOW);/*画时针*/
ang=minrate*360;
DrawPoly(MiHand,ang, GREEN);/*画分针*/
ang=secrate*360;
DrawPoly(SecHand,ang, RED);/*画秒针*/
}
main()
{
int gdriver=EGA,
gmode=EGAHI;
int curpage;
struct time curtime ,newtime ;
initgraph(gdriver,gmode,"c:\\tc");
setbkcolor(BLUE);
cleardevice();
gettime(curtime);
curpage=0;
DrawClock(curtime);
while(1)
{
if(kbhit())
break; /*按任意键退出*/
gettime(newtime); /*检测系统时间*/
if(newtime.ti_sec!=curtime.ti_sec)/*每1秒更新一次时间*/
{
if(curpage==0)
curpage=1;
else
curpage=0;
curtime=newtime;
/*设置绘图页*/
setactivepage(curpage);
/*在图页上画表盘*/
DrawClock(curtime);
/*设置绘图页为当前可见页*/
setvisualpage(curpage);
/*0分0秒高声报时*/
if(newtime.ti_min==0newtime.ti_sec==0)
HighBeep();
/* 59分55至秒时低声报时*/
else if(newtime.ti_min==59
newtime.ti_sec=59)
LowBeep();/*其他时间只发出喀嗒声*/
else
Click();
}
}
closegraph();
}