昨天特意看了一下Eclipse的技巧,又一次体会到了它的强大,呵呵.
import javax.microedition.lcdui.Choice;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/*
* Created on 2005-1-26
*/
/**
* @author aol
*/
public class CommandTestMIDlet extends MIDlet implements CommandListener
{
List l;
private Display display;
/* (non-Javadoc)
* @see javax.microedition.midlet.MIDlet#startApp()
*/
public CommandTestMIDlet()
{
display = Display.getDisplay(this);
}
protected void startApp() throws MIDletStateChangeException
{
// TODO Auto-generated method stub
// Form f = new Form("Command 测试");
l = new List("测试一下Command",Choice.EXCLUSIVE);
l.append("周敏",null);
l.append("小强",null);
l.append("张毅",null);
Command c1 = new Command("确定",Command.OK,1);
Command c2 = new Command("退出",Command.STOP,2);
l.addCommand(c1);
l.addCommand(c2);
l.setCommandListener(this);
// l.removeCommand(c3);
//显示
display.setCurrent(l);
}
/* (non-Javadoc)
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp()
{
// TODO Auto-generated method stub
}
/* (non-Javadoc)
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean arg0) throws MIDletStateChangeException
{
// TODO Auto-generated method stub
}
public void commandAction(Command c, Displayable s)
{
String str = c.getLabel();
if(str.equals("确定"))
{
l.setTicker(new Ticker("跑马灯啊,跑马灯,哈哈哈........"));
}
else if(str.equals("退出"))
{
l.setTicker(null);
}
}
}
我的模拟器是用索爱的P800. 要是自己有一台就好了~~~