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

📄 progressbar.java.svn-base

📁 example2 众多JAVA实例源码...学习java基础的好帮手
💻 SVN-BASE
字号:
package opusmicro.demos.canvas;

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

/**
 * 模块功能:J2ME进度条
 */
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);
			}
		}
	}
}

⌨️ 快捷键说明

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