SKY外语计算机学习
标题:
时钟(只有秒表)待完善。。。
[打印本页]
作者:
rogan
时间:
2013-7-19 00:30
标题:
时钟(只有秒表)待完善。。。
activity
package com.rogan.clock;
import android.app.Activity;
import android.os.Bundle;
public class ClockActivity extends Activity {
private ClockView clockView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
clockView = new ClockView(this);
setContentView(clockView);
new Thread(new clockThread()).start();
}
/**
* Clock refresh
*/
class clockThread implements Runnable {
@Override
public void run() {
while (!Thread.currentThread().interrupted()) {
clockView.postInvalidate();
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
}
}
}
复制代码
clockview
package com.rogan.clock;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.view.View;
/**
* Created by Administrator on 13-7-9.
*/
public class ClockView extends View implements Runnable {
int mcount = 0;
private Paint mPaint = null;
public ClockView(Context context) {
super(context);
mPaint = new Paint();
new Thread(this).start();
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawColor(Color.BLACK);
mPaint.setAntiAlias(true);
mPaint.setStrokeWidth(3);
mPaint.setStyle(Paint.Style.STROKE);
mPaint.setColor(Color.WHITE);
canvas.drawCircle(200, 500, 200, mPaint);
if (mcount < 60) {
mcount++;
} else {
mcount = 0;
}
float x = (float)(200 + 200 * Math.sin((mcount * Math.PI)/30));
float y = (float)(300 + 200*(1- Math.cos((mcount * Math.PI)/30)));
switch (mcount) {
case 0:case 60: {
canvas.drawLine(200, 500, 200, 300, mPaint);
}
break;
default: {
canvas.drawLine(200.0f, 500.0f, x, y, mPaint);
}
}
}
@Override
public void run() {
}
public static void main(String[] args) {
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))) );
}
}
复制代码
作者:
骏马
时间:
2013-7-22 08:04
本帖最后由 sky_yx 于 2015-12-30 14:07 编辑
作者:
rogan
时间:
2013-7-24 13:42
骏马 发表于 2013-7-22 08:04
欢迎光临 SKY外语计算机学习 (http://join.skywj.com/)
Powered by Discuz! X2.5