import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
public class Midlet1 extends MIDlet implements CommandListener {
private Display dis;
/************ 歡迎介面 ***********/
private Form main;
private Command cmd_exit;
private Command cmd_wMsg;
/************ 短信編輯介面 ***********/
private TextBox tbMsg;
private Command cmd_back;
private Command cmd_cancle;
private Command cmd_Yes;
/************ 發送介面 ***********/
private TextBox tbPhone;
private Command cmd_send;
private Command cmd_PhoneBack;
public Midlet1() {
dis = Display.getDisplay(this);
/************ 歡迎介面 ***********/
cmd_exit = new Command("退出", Command.BACK, 1);
cmd_wMsg = new Command("寫短信", Command.SCREEN, 1);
main = new Form("歡迎你");
/************ 短信編輯介面 ***********/
tbMsg = new TextBox("短信編輯", "", 255, TextField.ANY);
cmd_back = new Command("返回", Command.BACK, 1);
cmd_cancle = new Command("取消", Command.BACK, 1);
cmd_send = new Command("发送", Command.SCREEN, 1);
/************ 發送介面 ***********/
tbPhone = new TextBox("電話號碼:", "", 11, TextField.NUMERIC);
cmd_Yes = new Command("確定", Command.SCREEN, 1);
cmd_PhoneBack = new Command("取消", Command.BACK, 1);
}
protected void startApp() throws MIDletStateChangeException {
/************ 歡迎介面 ***********/
main.addCommand(cmd_exit);
main.addCommand(cmd_wMsg);
dis.setCurrent(main);
main.setCommandListener(this);
/************ 短信編輯介面 ***********/
tbMsg.addCommand(cmd_back);
tbMsg.addCommand(cmd_send);
tbMsg.setCommandListener(this);
/************ 發送介面 ***********/
tbPhone.addCommand(cmd_Yes);
tbPhone.addCommand(cmd_PhoneBack);
tbPhone.setCommandListener(this);
dis.setCurrent(main);
}
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
}
protected void pauseApp() {
}
public void commandAction(Command arg0, Displayable arg1) {
if (arg0 == cmd_exit) {
this.notifyDestroyed();
} else if (arg0 == cmd_wMsg) {
dis.setCurrent(tbMsg);
} else if (arg0 == cmd_back) {
dis.setCurrent(main);
} else if (arg0 == cmd_send) {
dis.setCurrent(tbPhone);
} else if (arg0 == cmd_PhoneBack) {
dis.setCurrent(tbMsg);
} else if (cmd_Yes == arg0) {
System.out.println("短息成功发送");
System.out.println("目的地:" + tbPhone.getString());
System.out.println("短息内容:" + tbMsg.getString());
} else if (cmd_cancle == arg0) {
int i = tbMsg.getCaretPosition();
tbMsg.delete(i - 2, 1);
}
}
}