j2me的模仿寫短信平臺

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;

public class mainApp1 extends MIDlet implements CommandListener {

 private TextBox tbx = new TextBox("輸入信息:", "", 255, TextField.ANY);
 private Display dis = Display.getDisplay(this);
 private Ticker t=new Ticker("我來了");
 private Alert logo=new Alert("歡迎你的到來","kdsajfklajdklfjasl",null,AlertType.ALARM);
 private Command cmd_delete=new Command("刪除",Command.BACK,1);
 private Command cmd_insert=new Command("插入文本",Command.SCREEN,2);
 private Command cmd = new Command("獲取光標", Command.SCREEN, 1);

 protected void startApp() throws MIDletStateChangeException {
  // TODO Auto-generated method stub
  tbx.addCommand(cmd);
  tbx.addCommand(cmd_insert);
  tbx.addCommand(cmd_delete);
  //設置頭頂上滾動條
  tbx.setTicker(t);
  tbx.setCommandListener(this);
  dis.setCurrent(logo,tbx);
 }

 public void commandAction(Command arg0, Displayable arg1) {
  // TODO Auto-generated method stub

  if (arg0 == cmd) {
   int i = tbx.getCaretPosition();
   System.out.println(i);
  }
  if(arg0==cmd_insert)
  {
   tbx.insert("插入的文本",tbx.getCaretPosition());
  }
  if(arg0==cmd_delete)
  {
   tbx.delete(tbx.getCaretPosition()-1, 1);
  }
 }

 protected void pauseApp() {
  // TODO Auto-generated method stub

 }

 protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
  // TODO Auto-generated method stub

 }

}

發佈了30 篇原創文章 · 獲贊 3 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章