package com.brj.test;
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.TextBox;
import javax.microedition.lcdui.TextField;
import javax.microedition.lcdui.Ticker;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
/**
* Ticker的用法
* @author Administrator
*
*/
public class TestTicker extends MIDlet implements CommandListener {
private Display display;
private Command exit;
private Command back;
private Command showTicker;//显示Ticker
private Ticker ticker;
private Form mainFace;
private TextBox tickerContainer;//设置Ticker之用
public TestTicker() {
display = Display.getDisplay(this);
exit = new Command("Exit", Command.EXIT, 1);
back = new Command("Back", Command.BACK, 1);
showTicker = new Command("ShowTicker", Command.SCREEN, 1);
ticker = new Ticker("华为 456.02,中兴 135.32");
mainFace = new Form("Welcome");
tickerContainer = new TextBox("股票信息", "", 50,TextField.ANY);
}
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 {
mainFace.addCommand(exit);
mainFace.addCommand(showTicker);
mainFace.setCommandListener(this);
tickerContainer.addCommand(back);
tickerContainer.setCommandListener(this);
tickerContainer.setTicker(ticker);
display.setCurrent(mainFace);
}
public void commandAction(Command c, Displayable d) {
if(c == exit){
try {
this.destroyApp(false);
} catch (MIDletStateChangeException e) {
e.printStackTrace();
}
this.notifyDestroyed();
}
if(c == back){
display.setCurrent(mainFace);
}
if(c == showTicker){
display.setCurrent(tickerContainer);
}
}
}