tickerdemo.java
来自「j2me学习 简单例子」· Java 代码 · 共 89 行
JAVA
89 行
package example.demoseniorui.ticker;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* <p>J2ME Ticker Demo</p>
*
* @author 刘光辉
* @version 2009.02.02
*/
public class TickerDemo extends MIDlet implements CommandListener {
private static final String TICKER_TEXT = "This is a ticker see it " +
"scroll along the way... On and on it goes without " +
"stopping even for a second!";
private static final Command CMD_EXIT = new Command("Exit",Command.EXIT,1);
private boolean firstTime;
private Display display;
private Form mainForm;
private Ticker ticker;
/**
* <p>TickerDemo的构造函数</p>
*/
public TickerDemo() {
display = Display.getDisplay(this);
firstTime = true;
mainForm = new Form("Ticker");
mainForm.setCommandListener(this);
}
/**
* <p>启动程序,使MIDlet处于active状态</p>
* <p></p>
* @see javax.microedition.midlet.MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException {
if(firstTime){
ticker = new Ticker(TICKER_TEXT);
mainForm.setTicker(ticker);
firstTime = false;
}
mainForm.addCommand(CMD_EXIT);
display.setCurrent(mainForm);
}
/**
* <p>暂停程序,使MIDlet处于pause状态</p>
* @see javax.microedition.midlet.MIDlet#pauseApp()
*/
protected void pauseApp() {
}
/**
* <p>销毁程序,使MIDlet处于destroyed状态</p>
*
* @param boolean unconditional
* <ul>true 释放资源保存数据进入destroyed状态,false 抛出异常保持当前状态</ul>
* @see javax.microedition.midlet.MIDlet#destroyApp(boolean)
*/
protected void destroyApp(boolean unconditional) throws MIDletStateChangeException {
display.setCurrent(null);
notifyDestroyed();
}
/**
* <p>命令处理函数,实现CommandListener接口</p>
* @param Command c 命令对象
* @param Displayable d 被放置到显示屏显示的对象
*/
public void commandAction(Command c, Displayable d) {
if(c == CMD_EXIT){
try {
destroyApp(true);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?