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

📄 alertdemo.java

📁 J2ME常用控件使用的例子 Eclipse写的 练手用的
💻 JAVA
字号:
package alert;

import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
import javax.microedition.lcdui.*;

public class AlertDemo extends MIDlet implements CommandListener {

	private final static Command CMD_EXIT = new Command("退出", Command.EXIT, 1);
	private Alert alert;
	private Form form;
	private final int timeout = 9000;
	public AlertDemo() {
		// TODO 自动生成构造函数存根
		try{
			alert = new Alert("Alert加载界面","Alert加载中……",
					Image.createImage("/res/information.png"),AlertType.INFO);
			alert.setTimeout(Alert.FOREVER);
			Gauge indicator = createIndicator(timeout);  // 用超时时间创建指示器,即进度条
			alert.setIndicator(indicator);
		}catch(java.io.IOException e){
			System.out.println("发生错误:" + e);
		}
		form = new Form("新界面");  // 生成表单
		form.append("Alert has done!");  // 添加字符串
		form.addCommand(CMD_EXIT);  // 添加软键
		form.setCommandListener(this);  // 添加软键事件侦听器
	}

	public void startApp() throws MIDletStateChangeException {
		// TODO 自动生成方法存根
		Display.getDisplay(this).setCurrent(alert,form);  //显示消息对话框,并指定下一屏幕

	}

	public void pauseApp() {
		// TODO 自动生成方法存根

	}


	public void destroyApp(boolean arg0){
		// TODO 自动生成方法存根

	}
	
	public void commandAction(Command c, Displayable d){
		if(c == CMD_EXIT){
			this.destroyApp(false);
			notifyDestroyed();
		}
	}
	private Gauge createIndicator(int maxValue){
		if(maxValue == Alert.FOREVER){
			return new Gauge(null, false, Gauge.INDEFINITE, Gauge.CONTINUOUS_RUNNING);
		}
		final int max = maxValue/1000;  // 指示器的最大值
		final Gauge indicator = new Gauge(null, false, max,0);
		new Thread(){
			public void run(){
				int value = 0;
				while(value<max){
					value ++;
					indicator.setValue(value);
					try{
						Thread.sleep(100);
					}catch(InterruptedException ie){
						System.out.println("发生错误:" + ie);
					}
				}
				System.out.println("滚动条结束!");
			}
		}.start();  // 启动线程
		return indicator;  // 返回指示器
	}
}

⌨️ 快捷键说明

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