www.pudn.com > 50code.rar > MyUI.java, change:2007-02-26,size:1776b


package demo; 
import javax.microedition.lcdui.Graphics; 
import javax.microedition.lcdui.Image; 
import javax.microedition.lcdui.game.GameCanvas; 
 
public class MyUI { 
	//定义一组表示界面显示状态的数值 
	public static final int UI_TITLE 		= 0;	//显示标题画面 
	public static final int UI_HIDE 		= 1;	//隐藏界面 
	public static final int UI_STATE_NUM	 = 2;	//界面状态总数 
	private int m_nState = UI_TITLE;				//当前的界面类型 
	 
	private Image m_TitleImg;						//标题画面图像 
	 
	public MyUI(){ 
		try{				//读取标题图像 
			m_TitleImg = Image.createImage("/demo/title.png"); 
		} 
		catch (Exception ex){}  
	} 
	/***** 
	 * 获取当前的界面显示类型 
	 * @返回:当前界面的显示类型 
	 */ 
	public int getState(){ 
		return m_nState; 
	} 
	/***** 
	 * 设置当前的界面显示类型,并进行出错处理 
	 * @参数 nType.........要设置的显示类型 
	 */ 
	public void setState( int state ){ 
		if( state < 0 || state >= UI_STATE_NUM ) 
			return; 
		m_nState = state;		 
	} 
	/***** 
	 * 处理按键的输入 
	 * @参数 keyStates.....当前的按键状态 
	 */ 
	public void Input( int keyStates ){ 
		switch( m_nState ){ 
		case UI_TITLE: 
			if( ( keyStates & GameCanvas.FIRE_PRESSED ) != 0 ) 
				setState(UI_HIDE); 
			break; 
		case UI_HIDE: 
			break; 
		} 
	} 
	/***** 
	 * 显示界面内容 
	 * @参数 g.............对应显示屏幕 
	 * @参数 scrWidth......屏幕的宽 
	 * @参数 scrHeight.....屏幕的高 
	 */ 
	public void Paint( Graphics g, int scrWidth, int scrHeight ){ 
		int x = scrWidth; 
		int y = scrHeight; 
		switch( m_nState ){ 
		case UI_TITLE:				//显示标题画面 
			if( m_TitleImg != null ){ 
				x = ( x - m_TitleImg.getWidth() ) / 2; 
				y = ( y - m_TitleImg.getHeight() ) / 2; 
				g.drawImage(m_TitleImg, x, y, 0 ); 
			} 
			break; 
		case UI_HIDE:				//隐藏界面 
			break; 
		} 
	} 
}