j2me学习笔记【10】——Ticker类实现在屏幕上横向滚动文本

package mtk; 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; public class TickerList extends MIDlet implements CommandListener { private Display display; private List list; private final String welcome; private final String hello; private Ticker ticker; private final static Command CMD_EXIT=new Command("退出",Command.EXIT,1); private final static Command SUBMIT=new Command("提交",Command.SCREEN,1); public TickerList() { display=Display.getDisplay(this); welcome=new String("欢迎您来到j2me编程世界,这是一个奇妙的世界"); hello=new String("hello"); ticker=new Ticker(welcome); list=new List("实例",Choice.EXCLUSIVE); list.append("欢迎", null); list.append("hello", null); list.addCommand(CMD_EXIT); list.addCommand(SUBMIT); list.setCommandListener(this); list.setTicker(ticker); } protected void destroyApp(boolean arg0){ } protected void pauseApp() { } protected void startApp() throws MIDletStateChangeException { display.setCurrent(list); } public void commandAction(Command c, Displayable d) { if(c==CMD_EXIT){ destroyApp(false); notifyDestroyed(); }else{ if(c==SUBMIT){ if(list.getSelectedIndex()==0){ ticker.setString(welcome); }else{ ticker.setString(hello); } } } } }

你可能感兴趣的:(j2me学习笔记【10】——Ticker类实现在屏幕上横向滚动文本)