//表盘分割成60分,将分割点的坐标存放在数组中
for(int i = 0; i60; i++){
point_x[i+1] = point_x[i]*Math.cos(jiaodu)-Math.sin(jiaodu)*point_y[i];
point_y[i+1] = point_y[i]*Math.cos(jiaodu) + point_x[i]*Math.sin(jiaodu);
}
point_x[60] = 0; point_y[60] = -120;
for(int i = 0; i60; i++){
scaled_x[i+1] = scaled_x[i]*Math.cos(jiaodu)-Math.sin(jiaodu)*scaled_y[i];
scaled_y[i+1] = scaled_y[i]*Math.cos(jiaodu) + Math.sin(jiaodu)*scaled_x[i];
【java60秒倒计时代码的简单介绍】}
scaled_x[60]= 0;
scaled_y[60] = -140;
}
public void start(){
//每当小程序重新开始时,首先消灭线程,然后重新开始创建线程
if(start_count = 1){
tSecond.interrupt();
tMinute.interrupt();
tHour.interrupt();
}
tSecond = new Thread(this);
tMinute = new Thread(this);
tHour= new Thread(this);
tSecond.start();
tMinute.start();
tHour.start();
start_count++;
if(start_count = 2) start_count = 1;
}
public void stop()
{
tSecond.interrupt();
tMinute.interrupt();
tHour.interrupt();
}
public void paint(Graphics g){
this.start();
g.drawOval(50,50,300,300);//表盘的外圈
g.translate(200,200);
//绘制表盘的小刻度和大刻度
for(int i = 0 ; i60; i++){
if(i%5 == 0){
g.setColor(Color.BLACK);
g.fillOval((int) scaled_x[i],(int) scaled_y[i],10,10);
}
else
g.fillOval((int)scaled_x[i],(int)scaled_y[i],5,5);
}
}
public void run(){
//获取本地时间
Date date = new Date();
String s=date.toString();
hour=Integer.parseInt(s.substring(11,13));
minute = Integer.parseInt(s.substring(14,16));
second = Integer.parseInt(s.substring(17,19));
if(Thread.currentThread() == tSecond){
second_a =(int)point_x[second];
second_b = (int)point_x[second];
g_second.drawLine(0,0,second_a,second_b);//秒针的初始位置
g_second.drawString("秒",second_a,second_b);
int i = second;
while(true){
try{
tSecond.sleep(1000);
Color c = getBackground();
g_second.setColor(c);
g_second.drawLine(0,0,second_a,second_b);//用背景色清除前一秒时的秒针
g_second.drawString("秒",second_a,second_b);
//如果秒针与分针重合,恢复分针的显示
if((second_a == minute_a)(second_b == minute_b)){
g_minute.drawLine(0,0,minute_a,minute_b);
g_minute.drawString("分",minute_a,minute_b);
}
//如果秒针与时针重合,恢复时针的显示
if((second_a == hour_a)(second_b == hour_b)){
g_hour.drawLine(0,0,hour_a,hour_b);
g_hour.drawString("时",hour_a,hour_b);
}
}
catch(InterruptedException e){
Color c = getBackground();
g_second.setColor(c);
g_second.drawLine(0,0,second_a,second_b);//用背景色清除秒针
g_second.drawString("秒",second_a,second_b);
return;
}
//秒针向前走一个单位
second_a=(int)point_x[(i+1)%60];
second_b = (int)point_y[(i+1)%60]; //每一秒走6度(一个单位格)
g_second.setColor(Color.red);
g_second.drawLine(0,0,second_a,second_b);
g_second.drawString("秒",second_a,second_b);
i++;
}
}
if(Thread.currentThread() == tMinute){
minute_a = (int)point_x[minute];
minute_b = (int)point_y[minute];
g_minute.drawLine(0,0,minute_a,minute_b);
int i = minute;
while(true){
//第一次过60-second秒就前进一分钟,以后每过60秒前进一分钟
try{
tMinute.sleep(1000*60 - second*1000);
second = 0;
Color c = getBackground();
g_minute.setColor(c);
g_minute.drawLine(0,0,minute_a,minute_b);
g_minute.drawString("分",minute_a,minute_b);
if((hour_a == minute_a)(hour_b== minute_b)){
推荐阅读
- 如何购买无人直播软件,无人直播怎么赚钱
- 直播间开场音乐是什么,直播开场曲
- 真人射击游戏场地广西汕头,真人射击游戏体验馆在哪里
- 传统媒体如何借力新媒体,传统媒体如何借力新媒体营销
- php无法链接数据库 php无法连接数据库
- oracle删掉用户表空间,oracle 删除用户表空间
- 联想cpu显卡怎么样,联想显卡性能排名
- 阿里云服务器端口如何打开,阿里云如何开放端口
- c语言接收键符函数 c语言接收字符