waitcanvas.java

来自「手机在线系统 采用Java 中的J2ME, JSP 跟MySql 运行环」· Java 代码 · 共 193 行

JAVA
193
字号
/**
 * @(#)WaitCanvas.java	1.11 01/08/23
 * Copyright (c) 2004-2005 wuhua of workroom Inc. All Rights Reserved.
 * @version 	1.0, 10/05/2004
 * @author 	饶荣庆
 * @author 	余煜辉
 */

 /**
 *此common包是连网的共有包,为所有连网提供统一的接口
 */
package com.j2me.common;

import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;

/**
 *此类是为了网络下载时候用户等待时的界面
 */
public  abstract class WaitCanvas extends Canvas 
{
	public Display display;

	/*定义下载好后要显示的下一个界面*/
	public Displayable displayAble;

	public Timer timer; //记时器类

	public int mCount = 0;
	public int mMaximum = 36;
	public int mInterval = 100;
  
	public int mWidth = getWidth();
	public int mHeight = getHeight();
	public int mX, mY, mRadius;
    
	/*判断是否下载完了,如果完了,则显示下个界面*/
	public boolean isNext;

	/*等待信息*/
	public String mMessage;
    
	/*此变量是用来显示下载的进度*/
	public int i; 
	//public String htmlURL;
	//public String imageURL;
	
   /*——---------------------------------------------------------
    *构造函数构造等待界面的初始化信息
	*/
	public WaitCanvas()
	{   
		// Calculate the radius.
		int halfWidth = (mWidth - mRadius) / 2;
		int halfHeight = (mHeight - mRadius) / 3;
		mRadius = Math.min(halfWidth, halfHeight);
		
		// Calculate the location.
		mX = halfWidth - mRadius / 2;
		mY = halfHeight - mRadius / 2;
		

		// Create a Timer to update the display.
		timer= new Timer();
		ScrollTask st = new ScrollTask();	//每个时间隔要运行程序的内部对象
		this.timer.schedule(st, 100, 100);   //锁定时间进度为0.1秒,并放置这个时间隔要运行的程序。		
	}

	/*显示窗体的方法*/
	/*public  void showForm(Display display, Displayable displayAble)	//用来显示界面
	{
		this.display = display;
	   	this.displayAble = displayAble;
		this.display.setCurrent(this);
	}*/	
    
	/*显示窗体的方法*/
	public  void showForm(Display display)	//用来显示界面
	{
		this.display = display;
		this.display.setCurrent(this);
	}	

	public void setNext(boolean isNext)
	{
		isNext = isNext;
	}

	/**
	 *开始从服务器上下载数据
	 */
	/*public void startDownloadHtml(String htmlURL)
	{
		d_H_T = new DownloadImageThread(htmlURL);
		d_H_T.start();
	}
	*/
	/**
	 *开始从服务器上下载图象
	 */
	/*public void startDownloadImage(String htmURL)
	{

	}
	*/

	/**
	 *抽象方法,给以后继承提供一个很好的接口
	 */
	public abstract void download();

	/**
	 *设置等待信息
	 */
	public void setMessage(String s) 
	{
		mMessage = s;
		repaint();
	}
	
	public void paint(Graphics g)
	{
		int theta = -(mCount * 360 / mMaximum);
		
		// Clear the whole screen.
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, mWidth, mHeight);
    
		
		// Now draw the pinwheel.
		g.setColor(150, 10, 0);
		g.drawArc(mX, mY, mRadius, mRadius, 0, 360);
		g.fillArc(mX, mY, mRadius, mRadius, theta +  90, 90);
		g.fillArc(mX, mY, mRadius, mRadius, theta + 270, 90);
		
		// Draw the message, if there is a message
		if (mMessage != null)
		{
			g.setColor(200, 10, 50);
			/*绘制动态文字*/
			switch (i)
			{
				case 0: g.drawString(mMessage, mWidth / 3, mHeight - 20, Graphics.LEFT | Graphics.TOP); break;
				case 1: g.drawString(mMessage + "。", mWidth / 3 , mHeight - 20, Graphics.LEFT | Graphics.TOP); break;
			    case 2: g.drawString(mMessage + "。。", mWidth / 3 , mHeight - 20, Graphics.LEFT | Graphics.TOP); break;
				case 3: g.drawString(mMessage + "。。。", mWidth / 3 , mHeight - 20, Graphics.LEFT | Graphics.TOP); break;
				case 4: g.drawString(mMessage + "。。。。", mWidth / 3 , mHeight - 20, Graphics.LEFT | Graphics.TOP); break;
				case 5: g.drawString(mMessage + "。。。。。", mWidth / 3 , mHeight - 20, Graphics.LEFT | Graphics.TOP); break;
				case 6: g.drawString(mMessage + "。。。。。。", mWidth / 3 , mHeight - 20, Graphics.LEFT | Graphics.TOP); break;
			}
			if (i == 6)
			{
				i = 0;
			}
			else 
			{
				i++;
			}
		}
			
	}

        /**
	     *内部类对象,用于动画的计时器
	     */
	    public class ScrollTask extends TimerTask
		{
			public void run() 
			{
				mCount = (mCount + 1) % mMaximum;
				repaint();
				if (isNext)
				{
					display.setCurrent(displayAble);
					//取消记时器
                    timer.cancel();
				}
				

				/*if (d_I_T != null && d_H_T != null && d_I_T.isOk() && d_H_T.isOk())
				{

					display.setCurrent(displayAble);
					//取消记时器
                    timer.cancel();
				}*/

			}

		}
}

⌨️ 快捷键说明

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