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

📄 iconmenu.java

📁 j2me手机图书阅读器
💻 JAVA
字号:
/********************************************************************
 * 
 * 版权说明,此程序仅供学习参考。不能用于商业
 * 
 ********************************************************************/
package org.pook.ui;

import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import org.pook.file.BookFileManager;
import org.pook.log.Log;
import org.pook.ui.core.Platform;
import org.pook.ui.util.GraphicsUtil;

/**
 * <b>类名:IconMenu.java</b> </br> 编写日期: 2006-9-15 <br/> 程序功能描述�? <br/> Demo:
 * <br/> Bug: <br/>
 * 
 * 程序变更日期 �?<br/> 变更作�?? �?<br/> 变更说明 �?<br/>
 * 
 * @author wuhua </br> <a href="mailto:rrq12345@163.com">rrq12345@163.com</a>
 */
public class IconMenu extends Menu {
	private static Log log = Log.getLog("IconMenu");
    
	 
 
	private Image arrow;
	
	public IconMenu(Image[] icons, Image arrow) {
		super(icons, null);
		this.arrow = arrow;
		changeViewAndSize();
		
	}
	
	public void changeViewAndSize(){
		if (Platform.HEIGHT   > view[HEIGHT]) {
			view[HEIGHT] = Platform.HEIGHT ;
			this.menuHeight = Platform.HEIGHT / this.numOfEls;
		}
		
	}

	/**
	 * 绘制菜单
	 */
	private void paintMenu(Graphics g) {
		GraphicsUtil.fillScreen(g, 0xFFD84F, 0, 0, Platform.WIDTH, Platform.HEIGHT); 
		paintIconMenu(g);
	}

	public void paint(Graphics g) {
		changeViewAndSize();
		paintMenu(g);

	}

	public void onClick(int keyCode) {

		thisLeftAndDown(keyCode);
		thisUpAndDown(keyCode);
	}

	/**
	 * 绘制图标菜单
	 * 
	 * @param g
	 */
	private void paintIconMenu(Graphics g) {
		int iconWidth = 0 ;
		int iconHeight = 0;
		for(int i = 0; i < this.numOfEls; i ++){
			iconWidth = icons[i].getWidth();
			iconHeight = icons[i].getHeight();
			GraphicsUtil.drawImageMiddle(g, icons[i], Platform.WIDTH/2, 0 + icons[i].getHeight()/2  + this.menuHeight * i);
		}
		
		
		paintArrow(g, (Platform.WIDTH - iconWidth)/4, iconHeight/2  + this.menuHeight * this.selectIndex + (iconHeight - arrow.getHeight())/2);
	}

	/**
	 * 绘制选择�菜单
	 * 
	 * @param height
	 *             
	 */
	void paintArrow(Graphics g, int x, int y) {
		 
		GraphicsUtil.drawImageMiddle(g,arrow,x, y);

	}

	/**
	 * 左右事件
	 * 
	 * @param keyCode
	 */
	private void thisLeftAndDown(int keyCode) {
		if (this.numOfEls == 0)
			return;
		switch (keyCode) {
		case Platform.KEY_LEFT: {
			super.selectIndex = super.selectIndex == 0 ? this.numOfEls - 1
					: --super.selectIndex;
			break;

		}
		case Platform.KEY_RIGHT: {
			super.selectIndex = super.selectIndex == this.numOfEls - 1 ? 0
					: ++super.selectIndex;
			break;
		}
		}
	}

	/**
	 * 上下事件
	 * 
	 * @param keyCode
	 */
	private void thisUpAndDown(int keyCode) {
		if (this.numOfEls == 0)
			return;
		switch (keyCode) {

		case Platform.KEY_UP: {

			super.selectIndex = super.selectIndex <= 0 ? this.numOfEls - 1
					: --selectIndex;

			break;

		}
		case Platform.KEY_DOWN: {
			super.selectIndex = super.selectIndex >= this.numOfEls - 1 ? 0
					: ++selectIndex;

			break;
		}
		}
	}

}

⌨️ 快捷键说明

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