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

📄 graphicsonedemo.java

📁 j2me学习 简单例子
💻 JAVA
字号:
package example.demoprimaryui.graphicsone;

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

/**
 * <p>J2ME GraphicsOne Demo</p>
 * 
 * @author 刘光辉
 * @version 2009.02.02
 */
public class GraphicsOneDemo extends MIDlet implements CommandListener{

	private static final Command CMD_EXIT = new Command("Exit",Command.EXIT,1);
	private static final Command CMD_BACK = new Command("Back",Command.BACK,1);
	private static final Command CMD_GO = new Command("Go",Command.OK,1);
	private boolean firstTime ;
	private int go ;
	private Display display;
	private Displayable firstd;
	private Displayable twod;
	private Displayable threed;	
	private Displayable fourd;	
	
	/**
	 * <p>GraphicsOneDemo的构造函数</p>
	 */
	public GraphicsOneDemo() {
		firstTime = true;
		go = 0;
		display = Display.getDisplay(this);
	}

	/**
	 * <p>启动程序,使MIDlet处于active状态</p>
	 * <p></p>
	 * @see javax.microedition.midlet.MIDlet#startApp()
	 */
	protected void startApp() throws MIDletStateChangeException {
		if(firstTime){
			firstd = new Color();
			firstd.addCommand(CMD_EXIT);
			firstd.addCommand(CMD_GO);
			firstd.setCommandListener(this);
		}
		display.setCurrent(firstd);
	}
	
	/**
	 * <p>暂停程序,使MIDlet处于pause状态</p>
	 * @see javax.microedition.midlet.MIDlet#pauseApp()
	 */
	protected void pauseApp() {

	}

	/**
	 * <p>销毁程序,使MIDlet处于destroyed状态</p>
	 * 
	 * @param boolean unconditional 
	 * <ul>true 释放资源保存数据进入destroyed状态,false 抛出异常保持当前状态</ul>
	 * @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
	 */
	protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {

	}

	/**
	 * <p>命令处理函数,实现CommandListener接口</p>
	 * @param Command c 命令对象
	 * @param Displayable d 被放置到显示屏显示的对象
	 */
	public void commandAction(Command c, Displayable d) {
		if(c == CMD_EXIT){
			try {
				destroyApp(false);
			} catch (MIDletStateChangeException e) {
				e.printStackTrace();
			}
			notifyDestroyed();
		}
		else if(c == CMD_GO){	
			if(go == 0){
				go = 1;
				twod = new Line();
				
				twod.addCommand(CMD_BACK);
				twod.addCommand(CMD_GO);
				twod.setCommandListener(this);
				
				display.setCurrent(twod);
			}else if(go == 1){
				go = 2;
				threed = new Rectangle();
				
				threed.addCommand(CMD_BACK);
				threed.addCommand(CMD_GO);
				threed.setCommandListener(this);
				
				display.setCurrent(threed);
			}else if(go == 2){
				go = 3;
				fourd = new Pacer();
				
				fourd.addCommand(CMD_BACK);
				fourd.setCommandListener(this);
				
				display.setCurrent(fourd);
			}
		}
		else if(c == CMD_BACK){
			if(go == 1){
				go = 0;
				display.setCurrent(firstd);
			}else if(go == 2){
				go = 1;
				display.setCurrent(twod);
			}else if(go == 3){
				go = 2;
				display.setCurrent(threed);
			}
		}
		
	}

}

⌨️ 快捷键说明

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