⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sweepcanvas.java

📁 这是j2me的例子,可供初学者学习,里面有源代码,是我写的
💻 JAVA
字号:
/*
 * SweepCanvas.java
 *
 * Created on 2007年3月28日, 上午11:50
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package com.tan.ui;

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

/**
 *
 * @author USER
 */
public class SweepCanvas extends Canvas implements Runnable {
    private boolean mTrucking;
    private int mTheta;
    private int mBorder;
    private int mDelay;
    /** Creates a new instance of SweepCanvas */
    public SweepCanvas() {
        mTheta = 0;
        mBorder = 10;
        mDelay = 50;
    }
    
    public void start() {
        mTrucking = true;
        Thread t = new Thread(this);
        t.start();
    }
    
    public void stop() {
        mTrucking = false;
    }
    protected void paint(Graphics graphics) {
        int width = getWidth();
        int height = getHeight();
        graphics.setGrayScale(255);
        
        graphics.fillRect(0,0,width-1,height-1);
        int x  = mBorder;
        int y = mBorder;
        int w = width - mBorder *2;
        int h = height - mBorder *2;
        for (int i = 0; i < 8; i++) {
            graphics.setGrayScale((8-i)*32-16);
            graphics.fillArc(x,y,w,h,mTheta+i*10,10);
            graphics.fillArc(x,y,w,h,(mTheta+180)%360+i*10,10);
        }
    }
    
    public void run() {
        while(mTrucking) {
            mTheta = (mTheta+1)%360;
            repaint();
            try {
                Thread.sleep(mDelay);
            } catch(Exception e) {}
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -