3.開發MIDlets實例 1).任務陳述-----SaveMyMoney移動銀行應用的第一個屏幕上要顯示的消息為”Welcome to SaveMyMoney Bank!”,屏幕頂部有一個顯示消息"Welcome to the World of Mobile Banking!"的滾動文本;
第二個屏幕上要顯示的消息為"Dear Customer, , You can view your personal account information by entering your PIN number and sending it to the number 9002. If you have not received the PIN number, please contact us at our Head Office."屏幕頂部有一個顯示消息"Note: Your PIN number has been sent to you at your mailing address."的滾動文本
2).代碼如下-----
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
//需要實現lcdui類中的CommandListener接口
public class MB extends MIDlet implements CommandListener
{
//用Display類治理顯示和用戶的輸入
Display display;
Form form1;
Form form2;
//定義兩個滾動條ticker1,ticker2
Ticker ticker1;
Ticker ticker2;
static final Command okCommand = new Command("Info",Command.OK,1);
static final Command backCommand = new Command("Back",Command.BACK,0);
static final Command exitCommand = new Command("Exit", Command.STOP, 2);
public MB()
{
}
public void startApp() throws MIDletStateChangeException
{
ticker1 = new Ticker("Welcome to the World of Mobile Banking!");
ticker2 = new Ticker("Note: Your PIN number has been sent to you at your mailing address.");
display = Display.getDisplay(this);
form1 = new Form("SaveMyMoney");
form2 = new Form("CUSTOMER CARE");
StringItem strItem = new StringItem("Welcome to SaveMyMoney Bank!", "");
StringItem strItem1 = new StringItem("Dear Customer, ", "You can view your personal account information by entering your PIN number and sending it to the number 9002. If you have not received the PIN number, please contact us at our Head Office.");
form1.append(strItem);
form2.append(strItem1);
//把命令加入到屏幕,第一個屏幕的左軟鍵是Exit,右軟鍵是OK
form1.addCommand(exitCommand);
form1.addCommand(okCommand);
//監聽
form1.setCommandListener(this);
form1.setTicker(ticker1);
//設置主屏幕的當前顯示為Form1
display.setCurrent(form1);
}
public void pauseApp()
{
}
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
public void showForm1()
{
form1.addCommand(exitCommand);
form1.addCommand(okCommand);
form1.setCommandListener(this);
display.setCurrent(form1);
}
public void showForm2()
{
form2.addCommand(exitCommand);
form2.addCommand(backCommand);
form2.setCommandListener(this);
form2.setTicker(ticker2);
display.setCurrent(form2);
}
public void commandAction(Command cmd, Displayable displayable)