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

📄 testprogressgauge.java

📁 j2me测试实现httpconn和自己实现list等功能
💻 JAVA
字号:
/*
 * Created on 2005-2-26
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.favo.ui;

import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.AlertType;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

/**
 * @author liyong
 * 
 * TODO To change the template for this generated type comment go to Window -
 * Preferences - Java - Code Style - Code Templates
 */
public class TestProgressGauge extends MIDlet implements CommandListener {

	/**
	 *  
	 */
	Display display;

	Command workCmd;

	Command exitCmd;

	Form f;

	public TestProgressGauge() {
		super();
		// TODO Auto-generated constructor stub
		display = Display.getDisplay(this);
		workCmd = new Command("compute", Command.OK, 10);
		exitCmd = new Command("exit", Command.EXIT, 10);
		f = new Form("Test");
		f.setCommandListener(this);
		f.addCommand(workCmd);
		f.addCommand(exitCmd);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.microedition.midlet.MIDlet#startApp()
	 */
	protected void startApp() throws MIDletStateChangeException {
		// TODO Auto-generated method stub
		display.setCurrent(f);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.microedition.midlet.MIDlet#pauseApp()
	 */
	protected void pauseApp() {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
	 */
	protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.microedition.lcdui.CommandListener#commandAction(javax.microedition.lcdui.Command,
	 *      javax.microedition.lcdui.Displayable)
	 */
	public void commandAction(Command arg0, Displayable arg1) {
		// TODO Auto-generated method stub
		if (arg0 == workCmd) {
			ProgressObserver poUI = ProgressGaugeUI.getInstance();
			BackgroundTask bkTask = new BackgroundTask(poUI, arg1, display) {
				public boolean runTask() {
					System.out.println("task start!");
					alertScreen = new Alert(
							"user cancel",
							"you press the cancel button and the screen will jump to the main Form",
							null, AlertType.ERROR);
					alertScreen.setTimeout(Alert.FOREVER);
					needAlert = true;
					//do something first
					getProgressObserver().updateProgress(null);//手动更新
					try {
						Thread.sleep(3000);
					} catch (Exception e) {
						e.printStackTrace();
						return false;
					}
					getProgressObserver().updateProgress("sleepd 3s....                                                                                                            ");//手动更新
					//取消了此处的手动查询点
//					if (getProgressObserver().isStopped())
//						return;
					getProgressObserver().updateProgress(null);//手动更新
					//do something again
					try {
						Thread.sleep(3000);
					} catch (Exception e) {
						e.printStackTrace();
						return false;
					}
					getProgressObserver().setMax();//手动更新
					display.setCurrent(new Form("complete"));//跳转成功画面
					return true;
				}

				public void cancel() {
					this.interrupt();
				}
			};
			BackgroundTask.runWithProgressGauge(bkTask, "Sleep 6sssssssssssssssssssssss",
					"Sleep now....                                                           ", true, display);
		}else if(arg0==exitCmd){
			try {
				destroyApp(false);
			} catch (MIDletStateChangeException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			notifyDestroyed();
		}
	}

}

⌨️ 快捷键说明

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