import java.io.IOException;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class list1 extends MIDlet implements CommandListener{
Display dis;
List l=new List("请你选择操作",List.MULTIPLE); //EXCLUSIVE为显示选择单选,IMPLICIT为普通单选(可以指定被选中时的command对象),MULTIPLE为多选
Ticker t=new Ticker("......"); //滚动显式文字
String s1="楠木阿尼陀佛";
String s2="阿呢路亚";
private Command cmdOK=new Command("OK",Command.SCREEN,1); //主动抢占右软键
public list1() throws IOException{
// TODO Auto-generated constructor stub
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
// TODO Auto-generated method stub
}
protected void pauseApp() {
// TODO Auto-generated method stub
}
protected void startApp() throws MIDletStateChangeException {
// TODO Auto-generated method stub
Image img=null;
try {
img=Image.createImage("/12.png"); //获取图片资源,注意图片一定要放在res包内
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Font font=Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,Font.SIZE_LARGE); //设置字体样式
dis=Display.getDisplay(this); //感觉上Displayable类和Swing里面的Contends一样,属于框架上面的容器
dis.setCurrent(l);
l.append("删除该号码",img);
l.append("向该号码发送短信",null);
l.append("编辑该号码",null);
l.append("讲该号码设置为好友",null);
//l.delete(0); //删除列表项目
//l.set(2,"叼你啊", null);
//l.insert(3,"反叼翻你" , null);
//l.setCommandListener(this);
l.append("念佛", null);
l.append("讲耶稣", null);
l.setFont(1,font); //改变选项字体
l.setTicker(t); //设置滚动显示
l.addCommand(cmdOK); //添加按钮
l.setCommandListener(this); //添加监听器
}
public void commandAction(Command c, Displayable d) {
// TODO Auto-generated method stub
//l.setTitle(l.getString(l.getSelectedIndex()));
int size=l.size();
//多选项判断方法一,遍历isSelected
for(int i=0;i<size;i++)
if(l.isSelected(i))
System.out.println(l.getString(i)+": 被选中");
//多选项判断方法二,使用getSelectedFlags获取点击状态
boolean[] bs=new boolean[size];
l.getSelectedFlags(bs);
for(int i=0;i<size;i++)
if(bs[i])
System.out.println(l.getString(i)+": 被选中");
if(l.getSelectedIndex()==4||c==l.SELECT_COMMAND)
t.setString(s1);
if(l.getSelectedIndex()==5)
t.setString(s2);
}
}