导航:首页 > 编程语言 > java数字时钟

java数字时钟

发布时间:2022-04-28 02:21:09

1. HTML用java制作时钟

给你一个 秒钟能一秒一秒的跳动 的
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>数字时钟</title>
</head>
<script language="JavaScript">
<!--
function showTime()
{
myTime=new Date();
var monthArray=new Array("1月","2月","3月","4月","5月","6月","7月","8月","9月","10月","11月","12月");
var dayArray =new Array("星期日","星期一","星期二","星期三","星期四","星期五","星期六","星期日");
year=myTime.getYear();
date=myTime.getDate();
hours=myTime.getHours();
minutes=myTime.getMinutes();
seconds=myTime.getSeconds();
suf="AM";
if(hours>12)
{
suf="PM";
hours=hours-12;
}
if(hours==0)
hours=12;
if(minutes<=9)
minutes="0"+minutes;
if(seconds<=9)
seconds="0"+seconds;
theTime="<font size=2>今天是:</font><br><font size=4>"+
year+"年"+monthArray[myTime.getMonth()]+date+"日"+""+dayArray[myTime.getDay()]+
"</font><br><font size=2>当前时间:</font>"+
"<br><font size=4 face=Arial>"+hours+":"+minutes+":"+seconds+""+suf+"</font>";
DT.innerHTML=theTime;
setTimeout("showTime()",1000);
}
-->
</script>
<body onload="showTime()">
<span id=DT style="position:absolute;left=35px;top=15px"></span>
</body>
</html>

2. JAVA 24小时 数字时钟

如果我没记错的话,安装JDK的时候有一个DEMO的目录,里面就有你要的这个程序的源文件

3. 怎么用java编写时钟呀

import
java.util.*;
import
java.awt.*;
import
java.applet.*;
//impelements
Runnable
是线程程序的接口
public
class
Clock
extends
Applet
implements
Runnable
{
Thread
timer
=
null;
//
定义线程实体timer
int
xcenter
=
400,
ycenter
=
50;
int
Radius
=
ycenter
-
5;
public
void
init()
{
resize(400,
125);//
设置时钟程序的窗口大小
setBackground(Color.white);//
设置小应用程序的背景色
}
public
void
paint(Graphics
g)
{
int
xh,
yh,
xm,
ym,
xs,
ys,
s,
m,
h;
String
today;
Date
dat
=
new
Date();
//
定义时间类dat
s
=
dat.getSeconds();
//
获得时间秒
m
=
dat.getMinutes();
//
获得时间分
h
=
dat.getHours();
today
=
dat.toLocaleString();
//
获得字符串时间格式
g.clearRect(0,
0,
size().width,
size().height);
//
消除小应用程序
xcenter
=
xcenter
-
1;
//
向左移动一个像素点
if
(xcenter
<
-50)
xcenter
=
400;
//
如果xcenter小于-50,则回到初始位置
//
计算秒的坐标
xs
=
(int)
(Math.cos(s
*
3.14f
/
30
-
3.14f
/
2)
*
(Radius
-
5)
+
xcenter);
ys
=
(int)
(Math.sin(s
*
3.14f
/
30
-
3.14f
/
2)
*
(Radius
-
5)
+
ycenter);
//
计算分钟的坐标
xm
=
(int)
(Math.cos(m
*
3.14f
/
30
-
3.14f
/
2)
*
(Radius
-
10)
+
xcenter);
ym
=
(int)
(Math.sin(m
*
3.14f
/
30
-
3.14f
/
2)
*
(Radius
-
10)
+
ycenter);
//
计算小时的坐标
xh
=
(int)
(Math.cos((h
*
30
+
m
/
2)
*
3.14f
/
180
-
3.14f
/
2)
*
(Radius
-
20)
+
xcenter);
yh
=
(int)
(Math.sin((h
*
30
+
m
/
2)
*
3.14f
/
180
-
3.14f
/
2)
*
(Radius
-
20)
+
ycenter);
g.setColor(Color.darkGray);
//
设置颜色
g.drawString("9",
xcenter
-
(Radius
-
5),
ycenter
+
3);
//
显示时钟上的数字‘9’
g.drawString("3",
xcenter
+
(Radius
-
10),
ycenter
+
3);
//
显示时钟上的数字‘3’
g.drawString("12",
xcenter
-
5,
ycenter
-
(Radius
-
13));
//
显示时钟上的数字'12'
g.drawString("6",
xcenter
-
3,
ycenter
+
(Radius
-
10));
//
显示时钟上的数字'6'
g.drawString(today,
0,
125);
//
显示字符串时钟
g.drawLine(xcenter,
ycenter,
xs,
ys);
//
画秒针
g.setColor(Color.blue);
//
设置颜色
g.drawArc(xcenter
-
Radius,
ycenter
-
Radius,
2
*
Radius,
2
*
Radius,
0,
360);
//
画钟
g.drawLine(xcenter,
ycenter
-
1,
xm,
ym);
//
画分针
g.drawLine(xcenter
-
1,
ycenter,
xm,
ym);
//
画分针
g.drawLine(xcenter,
ycenter
-
1,
xh,
yh);
//
画时针
g.drawLine(xcenter
-
1,
ycenter,
xh,
yh);
//
画时针
}
public
void
start()
{
if
(timer
==
null)
{
timer
=
new
Thread(this);
//
生成Thread(多线程程序)的对象实体
timer.start();
//
启动生成的线程
}
}
public
void
stop()
{
timer.stop();
//
停止线程的工作
timer
=
null;
//
放掉Thread对象
}
public
void
run()
//
改方法用来定义线程体,一旦线程被启动执行,就开始执行这个方法
{
while
(timer
!=
null)
{
try
{
Thread.sleep(150);
//
使当前正在执行的线程进入睡眠时间由参数millis确定,
//
单位时间是毫秒,当这个时间过去,线程即可运行的
while
(timer
!=
null)
{
try
{
Thread.sleep(150);//
使用当前正在执行的线程进入睡眠时间由参数
//
millis确定,单位是毫秒,当这个时间过去,线程即为可运行的
}
catch
(InterruptedException
e)
{
}
repaint();
//
repaint所做的事其实是去调用方法uadate重画效应用程序
}
timer
=
null;
}
catch
(InterruptedException
e)
{
}
}
}
//
所做的工作是先将整个效应用程序区域清除,再去调用paint,完成重画的动作
public
void
update(Graphics
g)
{
paint(g);
}
}

4. 怎样用java 程序写一个时钟程序

面向对象思想写成:

下面是一个显示器类

publicclassDisplay{
privateintvalue;//现在的值
privateintlimit;//上限值
Display(intlimit){
this.limit=limit;
}
publicvoidincrease(){
value++;
if(value==limit){
value=0;
}
}
publicintgetValue(){
returnvalue;
}
publicstaticvoidmain(String[]args){
Displayd=newDisplay(24);
for(;;){
d.increase();
System.out.println(d.getValue());
}
}
}

下面创建一个时钟对象:

publicclassClock{
privateDisplayh=newDisplay(24);
privateDisplaymin=newDisplay(60);
privateDisplays=newDisplay(60);
publicvoidstart(){
for(;;){
s.increase();
if(s.getValue()==0){//如果分重置,小时+1
min.increase();
if(min.getValue()==0){//如果分重置,小时+1
h.increase();
}
}
System.out.printf("%02d:%02d:%02d ",h.getValue(),min.getValue(),s.getValue());//格式输出
}
}
publicstaticvoidmain(String[]args){
Clockclock=newClock();
clock.start();
}

5. 基于Java的数字时钟软件设计

import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.swing.JFrame;
import javax.swing.Timer;

public class test1 extends JFrame{
public test1(){
super();
setSize(300,100);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
Timer timer = new Timer(1000, new ActionListener(){
public void actionPerformed(ActionEvent evt) {
setTitle( new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
}
}
);
timer.start();
}

public static void main( String... args ){
new test1();
}
}

6. Java 获得纯数字格式的时间

Java 获得纯数字格式的时间有下面三种方法

方法 一
System.currentTimeMillis();
方法 二
Calendar.getInstance().getTimeInMillis();
方法 三
new Date().getTime();
以下是效率对比:
import java.util.Calendar;
import java.util.Date;

public class TimeTest {
private static long _TEN_THOUSAND=10000;
public static void main(String[] args) {
long times=1000*_TEN_THOUSAND;
long t1=System.currentTimeMillis();
testSystem(times);
long t2=System.currentTimeMillis();
System.out.println(t2-t1);
testCalander(times);
long t3=System.currentTimeMillis();
System.out.println(t3-t2);
testDate(times);
long t4=System.currentTimeMillis();
System.out.println(t4-t3);
}

public static void testSystem(long times){//use 188
for(int i=0;i<times;i++){
long currentTime=System.currentTimeMillis();
}
}

public static void testCalander(long times){//use 6299
for(int i=0;i<times;i++){
long currentTime=Calendar.getInstance().getTimeInMillis();
}
}

public static void testDate(long times){
for(int i=0;i<times;i++){
long currentTime=new Date().getTime();
}
}
}
因为很简单我就不加注释了,每种方法都运行1千万次,然后查看运行结果
187
7032
297

结果发现 System.currentTimeMillis() 这种方式速度最快
Calendar.getInstance().getTimeInMillis() 这种方式速度最慢,看看源码会发现,Canlendar因为要处理时区问题会耗费很多的时间。
所以建议多使用第一种方式。

7. 求一篇java程序:要求数字时钟(19:59以及圆盘两种表达方式)可修改时间。有个备忘录

推荐链接 你自己看看http://wenku..com/link?url=-g_ACgmsFJjZMOBnWQf5_CnYD-wrbfXEpL7Q-x_

如果你连怎么简单的东西都需要别人给你做的完完整整你。你其实可以放弃java了。编程只能靠自学,没能会逼你学的。这种时钟的代码 网上多的一比。自己好好想想!

8. 用JAVA写数字时钟

importjavax.swing.*;

importjava.awt.event.ActionListener;

importjava.awt.event.ActionEvent;

importjava.awt.*;

importjava.util.Calendar;

importjava.util.GregorianCalendar;

{

intx,y,x0,y0,r,h,olds_x,olds_y,oldm_x,oldm_y,oldh_x,oldh_y,ss,mm,hh,old_m,old_h,ang;

finaldoubleRAD=Math.PI/180;

publicClock(){

super("Clockbykikiwawa");

setDefaultCloseOperation(3);

setSize(200,200);

setBackground(Color.BLACK);

setLocation(300,150);

setResizable(false);

setVisible(true);

intdelay=1000;

ActionListenerdrawClock=newActionListener(){

publicvoidactionPerformed(ActionEventevt){

repaint();

}

};

newTimer(delay,drawClock).start();

}

publicvoidactionPerformed(ActionEvente){

}

publicvoidpaint(Graphicsg){

Graphics2Dg2D=(Graphics2D)g;

Insetsinsets=getInsets();

intL=insets.left/2,T=insets.top/2;

h=getSize().height;

g.setColor(Color.white);

g2D.setStroke(newBasicStroke(4.0f));

g.drawOval(L+40,T+40,h-80,h-80);

r=h/2-40;

x0=40+r-5+L;

y0=40+r-5-T;

ang=60;

for(inti=1;i<=12;i++){

x=(int)((r+10)*Math.cos(RAD*ang)+x0);

y=(int)((r+10)*Math.sin(RAD*ang)+y0);

g.drawString(""+i,x,h-y);

ang-=30;

}

Calendarnow=newGregorianCalendar();

intnowh=now.get(Calendar.HOUR_OF_DAY);

intnowm=now.get(Calendar.MINUTE);

intnows=now.get(Calendar.SECOND);

Stringst;

if(nowh<10)st="0"+nowh;elsest=""+nowh;

if(nowm<10)st+=":0"+nowm;elsest+=":"+nowm;

if(nows<10)st+=":0"+nows;elsest+=":"+nows;

g.setColor(Color.pink);

g.fillRect(L,T,50,28);

g.setColor(Color.blue);

g.drawString(st,L+2,T+26);

ss=90-nows*6;

mm=90-nowm*6;

hh=90-nowh*30-nowm/2;

x0=r+40+L;

y0=r+40+T;

if(olds_x>0){

g.setColor(getBackground());

g.drawLine(x0,y0,olds_x,h-olds_y);

}

else{

old_m=mm;

old_h=hh;

}

x=(int)(r*0.9*Math.cos(RAD*ss))+x0;

y=(int)(r*0.9*Math.sin(RAD*ss))+y0-2*T;

g.setColor(Color.yellow);

g.drawLine(x0,y0,x,h-y);

olds_x=x;

olds_y=y;

g2D.setStroke(newBasicStroke(2.2f));

if(old_m!=mm){

g.setColor(getBackground());

g.drawLine(x0,y0,oldm_x,h-oldm_y);

}

x=(int)(r*0.7*Math.cos(RAD*mm))+x0;

y=(int)(r*0.7*Math.sin(RAD*mm))+y0-2*T;

g.setColor(Color.green);

g.drawLine(x0,y0,x,h-y);

oldm_x=x;

oldm_y=y;

old_m=mm;

g2D.setStroke(newBasicStroke(3.4f));

if(old_h!=hh){

g.setColor(getBackground());

g.drawLine(x0,y0,oldh_x,h-oldh_y);

}

x=(int)(r*0.5*Math.cos(RAD*hh))+x0;

y=(int)(r*0.5*Math.sin(RAD*hh))+y0-2*T;

g.setColor(Color.red);

g.drawLine(x0,y0,x,h-y);

oldh_x=x;

oldh_y=y;

old_h=hh;

}

publicstaticvoidmain(String[]args){

Clockc=newClock();

}}

4

9. java 数字时钟 就是最简单的当前时间~

给你个最精简的swing。。。呵呵

importjava.awt.FlowLayout;

importjava.text.SimpleDateFormat;

importjava.util.Date;

importjava.util.Locale;

importjava.util.Timer;

importjava.util.TimerTask;

importjavax.swing.JFrame;

importjavax.swing.JLabel;

publicclassTest{

staticpublicvoidmain(String参数[]){

JFramef=newJFrame("时钟示例");

f.setLayout(newFlowLayout());

f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

f.setSize(200,50);

finalJLabell=newJLabel();

finalSimpleDateFormatformat=newSimpleDateFormat(

"y年M月d日EH:m:s",Locale.CHINA);

f.add(l);

Timert=newTimer();

t.scheleAtFixedRate(newTimerTask(){

@Override

publicvoidrun(){

l.setText(format.format(newDate(System.currentTimeMillis())));

}

},0,1000);

f.setVisible(true);

}

}

10. 用Java编写小时钟

貌似这个网上有JS插件的

阅读全文

与java数字时钟相关的资料

热点内容
java计算12 浏览:249
大金空调摆动式压缩机 浏览:453
新的云服务器如何设置首页 浏览:687
javastring字符位置 浏览:196
银河麒麟字体库存在哪个文件夹 浏览:956
魔兽加丁服务器的航空叫什么 浏览:152
花冠改装案例哪个app多 浏览:515
成绩单app哪个好用 浏览:140
北美程序员vs国内程序员 浏览:181
php解析xml文档 浏览:121
石墨文档APP怎么横屏 浏览:185
墙主钢筋加密和非加密怎么看 浏览:144
金山区文件夹封套定制 浏览:708
soho程序员 浏览:672
java字节截取 浏览:526
php提交作业 浏览:815
房产还没解压可以办理赠予吗 浏览:224
java毫秒转分钟 浏览:753
模式识别中文pdf 浏览:774
c语言平均数字编译错误 浏览:171