自己抽象的J2ME进度条

import  javax.microedition.lcdui.Display;
import  javax.microedition.lcdui.Displayable;
import  javax.microedition.lcdui.Graphics;

/**
 * 模块功能:J2ME进度条
 * 
@author midi
 *   midi13@gmail.com
 * 2007-7-14 15:20:21
 * 
@version 1.0
 * 
@since 2007
 * 
 
*/

public   class  ProgressBar  implements  Runnable  {
    
/** 进度条宽度 */
    
private int barWidth;

    
/** 进度条高度 */
    
private int barHeight;

    
/** 步长 */
    
private int barStep;

    
/** 最大步长(格子数)=barWidth/barStep */
    
private int barStepMax;

    
/** 进度条的游标 */
    
private int cursor = 0;

    
/** 进度条的x */
    
private int barX;

    
/** 进度条的y */
    
private int barY;

    
/** 背景色 */
    
private int bgColor;

    
/** 前景色 */
    
private int fgColor;

    
/** 是否完成进度 */
    
private boolean done = false;

    
/** Graphics对象 */
    
private Graphics g;

    
/** Display对象 */
    
private Display display;

    
/** 目标屏幕 */
    
private Displayable aim;

    
public ProgressBar(Display display, Displayable aim, Graphics g) {
        
this.display = display;
        
this.aim = aim;
        
this.g = g;
    }


    
/**
     * 初始化其他参数
     * 
     * 
@param barWidth
     * 
@param barHeight
     * 
@param barX
     * 
@param barY
     * 
@param bgColor
     * 
@param fgColor
     
*/

    
public void initialize(int barWidth, int barHeight, int barX, int barY,
            
int bgColor, int fgColor) {

        
this.barWidth = barWidth;
        
this.barHeight = barHeight;
        
this.barX = barX;
        
this.barY = barY;
        
this.bgColor = bgColor;
        
this.fgColor = fgColor;

        barStepMax 
= 10;
        barStep 
= barWidth / barStepMax;

    }


    
/**
     * 绘制进度条
     * 
     * 
@param g
     
*/

    
public void draw(Graphics g) {
        g.setColor(
this.bgColor);
        g.fillRect(
this.barX, this.barY, this.barWidth, this.barHeight);

        g.setColor(
this.fgColor);
        g.fillRect(
this.barX, this.barY, cursor * this.barStep, this.barHeight);
    }


    
public void run() {
        
while (!done) {
            draw(g);
            cursor
++;
            
if (cursor >= barStepMax) {
                done 
= true;
                display.setCurrent(aim);
            }

        }

    }

}

 
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值