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

📄 loadingcanvas.java

📁 一款模仿劲舞团的手机游戏
💻 JAVA
字号:

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 * @author trojan
 * 
 * ����������ʾ��ȡ����
 */
public class LoadingCanvas extends Canvas implements Runnable {

	private boolean isLoading = true;// ��ʶ�Ƿ����ڶ�ȡ

	private int loadingIndex = 0;// �����ʾ���ַ�

	private Image loadingImage;// ����ͼƬ

	private String percent = "";// Ҫ��ʾ������

	// ���췽��,���߳�
	public LoadingCanvas() {
		setFullScreenMode(true);
		initialize();
		new Thread(this).start();
	}

	// ��ʼ������
	protected void initialize() {
		// ��ȡ����ͼƬ
		loadingImage = createImage("/images/jg07.gif");
	}

	public void run() {
		// ������ڶ�ȡ,��ˢ��Loading����
		while (isLoading) {
			repaint();
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				// TODO �Զ���� catch ��
				e.printStackTrace();
			}
		}
	}

	// ��ͼ����
	protected void paint(Graphics g) {
		g.drawImage(loadingImage, getWidth() / 2, getHeight() / 2,
				Graphics.HCENTER | Graphics.VCENTER);
		g.setColor(0xffffffff);
		Font font = Font.getFont(Font.FACE_PROPORTIONAL, Font.STYLE_BOLD,
				Font.SIZE_LARGE);
		g.setFont(font);
		switch (loadingIndex) {
		case 0:
			g.drawString("Loading", (getWidth() / 2) - 35,
					getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
			break;
		case 1:
			g.drawString("Loading.", (getWidth() / 2) - 35,
					getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
			break;
		case 2:
			g.drawString("Loading..", (getWidth() / 2) - 35,
					getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
			break;
		case 3:
			g.drawString("Loading...", (getWidth() / 2) - 35,
					getHeight() / 2 + 30, Graphics.LEFT | Graphics.TOP);
			break;
		}
		loadingIndex = (loadingIndex + 1) % 4;

		if (!(percent.equals(""))) {
			g.drawString(percent, getWidth() / 2, getHeight() / 2 + 50,
					Graphics.HCENTER | Graphics.TOP);
		}
	}

	// ����ͼƬ
	protected Image createImage(String path) {
		Image image = null;
		try {
			image = Image.createImage(path);
		} catch (IOException e) {
			// TODO �Զ���� catch ��
			e.printStackTrace();
		}
		return image;
	}

	// �����ȡ
	public void endLoading() {
		isLoading = false;
	}

	// ����Ҫ��ʾ�İٷֱ�
	public void setPercent(String percent) {
		this.percent = percent;
	}
}

⌨️ 快捷键说明

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