手机上弄个动态的八卦图

 

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author user
 */
public class Midlet extends MIDlet {
  
    private RunBagua runBagua;
    public Midlet(){
    	runBagua=new RunBagua();
    }
    public void startApp() {
    	Display.getDisplay(this).setCurrent(runBagua);
        
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }
}



import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

public class RunBagua extends Canvas implements Runnable {
	int[] sin = {0,
			1736,
			3420,
			4999,
			6427,
			7660,
			8660,
			9396,
			9848,
			10000,
			9848,
			9396,
			8660,
			7660,
			6427,
			4999,
			3420,
			1736,
			0,
			-1736,
			-3420,
			-4999,
			-6427,
			-7660,
			-8660,
			-9396,
			-9848,
			-10000,
			-9848,
			-9396,
			-8660,
			-7660,
			-6427,
			-5000,
			-3420,
			-1736};
	int[] cos = {10000,
			9848,
			9396,
			8660,
			7660,
			6427,
			5000,
			3420,
			1736,
			0,
			-1736,
			-3420,
			-4999,
			-6427,
			-7660,
			-8660,
			-9396,
			-9848,
			-10000,
			-9848,
			-9396,
			-8660,
			-7660,
			-6427,
			-5000,
			-3420,
			-1736,
			0,
			1736,
			3420,
			5000,
			6427,
			7660,
			8660,
			9396,
			9848};
	int width;//屏幕的宽
	int height;//屏幕的高
	int R = 40;//八卦图的半径一半,即鱼头的半径
	int centerY;//八挂图的圆心Y坐标
	int centerX;//八挂图的圆心x坐标
	int[] cTempX = new int[36];
	int[] cTempY = new int[36];
	public RunBagua() {
		width = this.getWidth();
		height = this.getHeight();
		centerX = width / 2;
		centerY = height / 2;
		for (int i = 0; i < 36; i++) {
			cTempX[i] = centerX + R * cos[i] / 10000;
			cTempY[i] = centerY - R * sin[i] / 10000;
		}
		new Thread(this).start();
	}
	int m = 9;
	int m1 = 27;
	protected void paint(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, width, height);//刷屏
		
		int xL1 = cTempX[m] - R;
		int yL1 = cTempY[m] - R;
		int xL3 = cTempX[m1] - R;
		int yL3 = cTempY[m1] - R;
		int start1 = m * 10;
		int end1 = 180;
		int start3 = m1 * 10;
		int end3 = 180;
		g.setColor(0, 0, 0);
		g.drawArc(centerX-2*R, centerY-2*R, 4*R, 4*R, 0, 360);//画边缘边界
		
		g.fillArc(centerX-2*R, centerY-2*R, 4*R, 4*R, start1, end1);//画黑色半圆
		g.setColor(255, 255, 255);
		g.fillArc(centerX-2*R, centerY-2*R, 4*R, 4*R, start3, end3);//画白色半圆
		g.setColor(0, 0, 0);
		g.fillArc(xL3, yL3, 2 * R, 2 * R, start3, end3);//画黑色鱼头
		g.setColor(255, 255, 255);
		g.fillArc(xL1, yL1, 2 * R, 2 * R, start1, end1);//画白色鱼头
		g.fillArc(xL3+R-5, yL3+R-5, 10, 10, 0, 360);//画小白鱼眼
		g.setColor(0, 0, 0);
		g.fillArc(xL1+R-5, yL1+R-5, 10, 10, 0, 360);//画小黑鱼眼
		
	}
	/*
	 * 改变数据让八卦图动起来
	 * 
	 */
	public void update(){
		m = ++m > 35 ? 0 : m;
		m1 = ++m1 > 35 ? 0 : m1;
	}
	public void run() {
		while (true) {
			update();
			repaint();
			try {
				Thread.sleep(100);
			} catch (InterruptedException ex) {
				ex.printStackTrace();
			}
		}
	}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值