继续学习j2me的ui编程,下面是实现ticker的例子,运行就是这样子:
/*
一个简单的提示现实类,在每个窗体中只允许有一个该类的实例。
如下的例子。
其代码如同以前加载工程中一样,运行它,测试界面如下:
*/
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.midlet.MIDlet;
public class tickerdemo1 extends MIDlet implements CommandListener {
private static final String TICKER_TEXT =
"类似走马灯,又类似提示器。。。 " + "运行下看看。。。" ;
private boolean firstTime;
private Form mainForm;
private Command exitCommand = new Command("Exit", Command.EXIT, 1);
private Display myDisplay;
private Ticker t;
public tickerdemo1() {
myDisplay = Display.getDisplay(this);
firstTime = true;
mainForm = new Form("新窗体");
mainForm.setCommandListener(this);
}
protected void startApp() {
if (firstTime) {
t = new Ticker(TICKER_TEXT); //创建实例
mainForm.setTicker(t);
firstTime = false;
}
mainForm.addCommand(exitCommand);
myDisplay.setCurrent(mainForm);
}
protected void destroyApp(boolean unconditional) {
myDisplay.setCurrent((Displayable)null);
notifyDestroyed();
}
protected void pauseApp() {
}
public void commandAction(Command c, Displayable s) {
if (c == exitCommand) {
destroyApp(true);
}
}
}