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

📄 gaugetest.java

📁 java手机程序开发光盘源码(第六章)
💻 JAVA
字号:
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

public class GaugeTest extends MIDlet implements Runnable, CommandListener{

	Display display;
	Form form;
	Alert info;
	Gauge interactive, nonInteractive;
	Thread thread;
	Command exitCmd;
	Command pauseCmd;
	boolean isPaused = false;

	public GaugeTest(){
		display = Display.getDisplay(this);
		form = new Form("Gauge练习");
		info = new Alert("信息", "读取完毕", null, AlertType.INFO);
		thread = new Thread(this);
		interactive = new Gauge("设定间隔时间", true, 10, 1);
		nonInteractive = new Gauge("读取中......", false, 20, 0);
		exitCmd = new Command("退出", Command.EXIT, 1);
		pauseCmd = new Command("暂停/继续", Command.STOP, 1);
		form.append(interactive);
		form.append(nonInteractive);
		form.addCommand(exitCmd);
		form.addCommand(pauseCmd);
		form.setCommandListener(this);
		info.setTimeout(Alert.FOREVER);
	}


	public void startApp(){
		display.setCurrent(form);
		thread.start();

	}

	public void run(){
		while(true){
			if(!isPaused){
				int millisecond = interactive.getValue();
				try{
					Thread.sleep(500*millisecond);
				}
				catch(Exception ex){}
				if(nonInteractive.getValue() < nonInteractive.getMaxValue()){
					nonInteractive.setValue(nonInteractive.getValue()+1);
				}
				else{
					nonInteractive.setValue(0);
					isPaused = true;
					display.setCurrent(info, form);
				}
			}
		}
	}

	public void pauseApp(){
	}

	public void destroyApp(boolean unconditional){

	}

	public void commandAction(Command c, Displayable d){

		if(c == exitCmd){
			destroyApp(true);
			notifyDestroyed();
		}
		else if(c == pauseCmd){
			if(!isPaused){
				nonInteractive.setLabel("暂停读取");
			}
			else{
				nonInteractive.setLabel("读取中......");
			}
			isPaused = !isPaused;
		}
	}

}

⌨️ 快捷键说明

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