你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:技术专栏 / Java专栏
自己抽象的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);
            }

        }

    }

}

  推荐精品文章

·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录
·2023年10月目录
·2023年9月目录 
·2023年8月目录 
·2023年7月目录
·2023年6月目录 
·2023年5月目录
·2023年4月目录 
·2023年3月目录 
·2023年2月目录 
·2023年1月目录 

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089