www.pudn.com > WordTip.zip > IndexFunctionUI.java
/**
* Created on 2005-1-26
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package net.hyweb.ui;
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.List;
/**
* @author user
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class IndexFunctionUI extends List implements CommandListener {
private UIController uicontroller;
private static final String imagePath = "/icon";
private static final String[] items = {
"View All",
"Search word",
"Add new word",
"About"
};
public IndexFunctionUI(UIController uicontroller){
super("FUNCTION", List.IMPLICIT);
this.uicontroller = uicontroller;
//加载列表选项与图标
for(int i = 0; i < items.length; i++){
append(items[i], createImage(imagePath + (i % 2) + ".png"));
}
Ticker ticker = new Ticker("Developed by : 黄叶 www.hyweb.net");
setTicker(ticker);
this.setCommandListener(this);
}
private Image createImage(String name){
Image image = null;
try {
image = Image.createImage(name);
} catch (IOException e) {
e.printStackTrace();
}
return image;
}
/**
* IndexFunctionUI关联监听器,没有设定特殊的Command,通过ItemIndex来触发
*/
public void commandAction(Command command, Displayable display) {
//当为列表确定命令格式时,触发监听器动作
if(command == List.SELECT_COMMAND){
int itemIndex = getSelectedIndex();
switch(itemIndex + 100){
case EventID.VIEW_ALL:{
uicontroller.EventController(EventID.VIEW_ALL);
break;
}
case EventID.SEARCH_WORD:{
uicontroller.EventController(EventID.SEARCH_WORD);
break;
}
case EventID.ADD_NEW_WORD:{
uicontroller.EventController(EventID.ADD_NEW_WORD);
break;
}
case EventID.ABOUT:{
uicontroller.EventController(EventID.ABOUT);
break;
}
default:
break;
}
}
}
}