设为首页收藏本站

SKY外语、计算机论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 6531|回复: 2

[代码分享] 时钟(只有秒表)待完善。。。

[复制链接]

65

主题

3

好友

739

积分

超级版主

Rank: 8Rank: 8

自我介绍
新年第一天据说有雨,全民齐赏日出的计划恐要泡汤。”宋仁宗拍着包拯的肩,“朕决定把你悬挂在城门上。”“但微臣额上的不是太阳是月亮啊!”“没事,挂久一点就会升级成太阳
生肖
星座
狮子座
性别

最佳新人 活跃会员 热心会员 推广达人 宣传达人 灌水之王 突出贡献 优秀版主 论坛元老

发表于 2013-7-19 00:30:39 |显示全部楼层
activity
  1. package com.rogan.clock;
  2. import android.app.Activity;
  3. import android.os.Bundle;


  4. public class ClockActivity extends Activity {
  5. private ClockView clockView = null;
  6.     @Override
  7.     protected void onCreate(Bundle savedInstanceState) {
  8.         super.onCreate(savedInstanceState);
  9.         clockView = new ClockView(this);
  10.         setContentView(clockView);
  11.         new Thread(new clockThread()).start();
  12.     }

  13.     /**
  14.      * Clock refresh
  15.      */
  16.     class clockThread implements Runnable {
  17.         @Override
  18.         public void run() {

  19.             while (!Thread.currentThread().interrupted()) {
  20.                 clockView.postInvalidate();
  21.                 try {
  22.                     Thread.sleep(1000);
  23.                 } catch (InterruptedException e) {
  24.                     Thread.currentThread().interrupt();
  25.                 }
  26.             }
  27.         }
  28.     }
  29. }
复制代码
clockview
  1. package com.rogan.clock;
  2. import android.content.Context;
  3. import android.graphics.Canvas;
  4. import android.graphics.Color;
  5. import android.graphics.Paint;
  6. import android.view.View;

  7. /**
  8. * Created by Administrator on 13-7-9.
  9. */
  10. public class ClockView extends View implements Runnable {
  11.     int mcount = 0;
  12.     private Paint mPaint = null;

  13.     public ClockView(Context context) {
  14.         super(context);
  15.         mPaint = new Paint();
  16.         new Thread(this).start();
  17.     }

  18.     @Override
  19.     protected void onDraw(Canvas canvas) {
  20.         super.onDraw(canvas);
  21.         canvas.drawColor(Color.BLACK);
  22.         mPaint.setAntiAlias(true);
  23.         mPaint.setStrokeWidth(3);
  24.         mPaint.setStyle(Paint.Style.STROKE);
  25.         mPaint.setColor(Color.WHITE);
  26.         canvas.drawCircle(200, 500, 200, mPaint);

  27.         if (mcount < 60) {
  28.             mcount++;
  29.         } else {
  30.             mcount = 0;
  31.         }
  32.         float x = (float)(200 +  200 *  Math.sin((mcount * Math.PI)/30));
  33.         float y = (float)(300 + 200*(1- Math.cos((mcount * Math.PI)/30)));
  34.         switch (mcount) {
  35.             case 0:case 60: {
  36.                 canvas.drawLine(200, 500, 200, 300, mPaint);
  37.             }
  38.             break;

  39.             default: {
  40.                 canvas.drawLine(200.0f, 500.0f, x, y, mPaint);
  41.             }
  42.         }
  43.     }

  44.     @Override
  45.     public void run() {

  46.     }

  47.     public static void main(String[] args) {
  48.         System.out.println("sdf:x="+  (float)(200 +  200*1 *  Math.sin(Math.PI/30))+"y="+(float)(300 + 200*(1-1 * Math.cos(Math.PI/30))) );
  49.     }
  50. }
复制代码

0

主题

0

好友

486

积分

版主

Rank: 7Rank: 7Rank: 7

生肖
星座
水瓶座
性别

最佳新人 活跃会员 论坛元老

发表于 2013-7-22 08:04:01 |显示全部楼层
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑



回复

使用道具 评分 举报

65

主题

3

好友

739

积分

超级版主

Rank: 8Rank: 8

自我介绍
新年第一天据说有雨,全民齐赏日出的计划恐要泡汤。”宋仁宗拍着包拯的肩,“朕决定把你悬挂在城门上。”“但微臣额上的不是太阳是月亮啊!”“没事,挂久一点就会升级成太阳
生肖
星座
狮子座
性别

最佳新人 活跃会员 热心会员 推广达人 宣传达人 灌水之王 突出贡献 优秀版主 论坛元老

发表于 2013-7-24 13:42:16 |显示全部楼层
骏马 发表于 2013-7-22 08:04

回复

使用道具 评分 举报

您需要登录后才可以回帖 登录 | 立即注册


手机版|SKY外语计算机学习 ( 粤ICP备12031577 )    

GMT+8, 2024-3-29 16:52 , Processed in 0.166538 second(s), 29 queries .

回顶部