模拟时钟java论文
我给你贴个java的..
如果想要javascript,自己去百度搜,有很多。
导入Java . awt . color;
导入Java . util . *;
导入Java . awt . *;
导入Java . applet . *;
公共类时钟扩展Applet实现Runnable
{
线程计时器= null
标签label;
int lastxs=50,lastys=30,lastxm=50,lastym=30,lastxh=50,lastyh = 30
公共void init()
{
label =新标签(" ");
set background(color . white);
添加(标签);
}
公共空白油漆(图形g)
{
int xh,yh,xm,ym,xs,ys,s,m,h,xcenter,ycenter
Date right now = new Date();
string today = right now . tolocalestring();
label.setText(今天);
s = right now . get seconds();
m = right now . get minutes();
h = right now . get hours();
xcenter = 100;
ycenter = 80
xs =(int)(math . cos(s * 3.14f/30-3.14f/2)* 45+xcenter);
ys =(int)(math . sin(s * 3.14f/30-3.14f/2)* 45+y center);
XM =(int)(math . cos(m * 3.14f/30-3.14f/2)* 45+xcenter);
ym =(int)(math . sin(m * 3.14f/30-3.14f/2)* 45+y center);
xh =(int)(math . cos((h * 30+m * 2)* 3.14f/180-3.14f/2)* 30+xcenter);
yh =(int)(math . sin((h * 30+m * 2)* 3.14f/180-3.14f/2)* 30+y center);
g.setFont(新字体(“TimesToman”,字体。平原,14));
g . set color(color . orange);
g.fill3DRect(xcenter-50,ycenter-50,100,100,true);
g . set color(color . dark gray);
g .拉绳(" 12 ",xcenter-5,y center-37);
g.drawString("3 ",xcenter+40,y center+3);
g .拉绳(" 6 ",xcenter-3,y center+45);
g .拉绳(" 9 ",xcenter-45,y center+3);
g . set color(color . orange);
如果(xs!=lastxs||ys!=lastys)
{
g.drawLine(xcenter,ycenter,lastxs,lastys);
}
如果(xm!=lastxm||ym!=lastym)
{
g.drawLine(xcenter,ycenter-1,lastxm,lastym);
g.drawLine(xcenter-1,ycenter,lastxm,lastym);
}
if(xh!=lastxh||yh!=lastyh)
{
g.drawLine(xcenter,ycenter-1,lastxh,last yh);
g.drawLine(xcenter-1,ycenter,lastxh,last yh);
}
g . set color(color . red);
g.drawLine(xcenter,ycenter,xs,ys);
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);
lastxs = xs
lastys = ys
lastxm = xm
lastym = ym
lastxh = xh
lastyh = yh
}
公共void开始()
{
if(timer==null)
{
timer =新线程(this);
timer . start();
}
}
公共无效站点()
{
timer = null
}
公共无效运行()
{
while(定时器!=空)
{
尝试
{
thread . sleep(1000);
} catch(interrupted exception ie){ }
repaint();
}
timer = null
}
公共void更新(图形g)
{
油漆(克);
}
}