Calendar now = new GregorianCalendar();
int nowh = now.get(Calendar.HOUR_OF_DAY);
int nowm = now.get(Calendar.MINUTE);
int nows = now.get(Calendar.SECOND);
String st=fmTime.format(now.getTime());
//在窗体上显示时间
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;
g2D.setStroke(new BasicStroke(1.2f));
//擦除秒针
//if(olds_x0){
//g.setColor(getBackground());
//// g.setColor(Color.gray);
//g.drawLine(x0, y0, olds_x, h-olds_y); // (?)
//}
//绘制秒针
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(new BasicStroke(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(new BasicStroke(3.2f));
//擦除时针
//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;
}
public static void main(String[] args){
new ClockPointer();
}
}
//整理一下
怎么用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
-
【好的时钟java代码 java时钟程序代码】3.14f
推荐阅读
- 空间文章公众号推荐,怎么搜空间公众号
- jquery字符转换成数字,jquery 字符串替换
- 女性的体育竞技叫什么游戏,女性的体育竞技叫什么游戏名字
- php数据库需要什么 php需要数据库吗
- linuxpythondev安装的简单介绍
- 区块链物流应用,区块链物流应用场景
- 火箭直播技巧视频app,火箭直播在线直播观看
- php数据库一对多 php查询数据库输出多个结果
- go语言模版语法怎么样,go语言模块