?? textboxdemo.java
字號(hào):
/*
* TextBoxDemo.java
*
* Created on 2005年3月5日, 下午10:50
*/
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
/**
*
* @author Liu Bin
* @version 1.0
*/
public class TextBoxDemo extends MIDlet
implements CommandListener {
//Display管理
Display display = null;
//TextBox對(duì)象
TextBox tb = new TextBox("TextBox功能演示", //設(shè)置標(biāo)題
"文本可能會(huì)超出屏幕能夠的顯示的數(shù)量," + //設(shè)置內(nèi)容
"在不同的手機(jī)上也可能顯示出不同的效果," +
"這些跟設(shè)備硬件密切相關(guān)",
100, //設(shè)置最大字符數(shù)
TextField. ANY); //可以接受任何輸入
//Ticker對(duì)象
Ticker ticker = new Ticker("這是滾動(dòng)文字");
//創(chuàng)建命令按鈕
static final Command cmdInsertFirst =
new Command("在開(kāi)始插入", Command.ITEM,1);
static final Command cmdDeleteBeforeChar =
new Command("刪除第一個(gè)字符", Command.ITEM,1);
static final Command cmdDeleteAfterChar =
new Command("刪除最后一個(gè)字符", Command.ITEM,1);
static final Command cmdReplaceLast =
new Command("替換", Command.ITEM,1);
static final Command cmdGetString =
new Command("文字內(nèi)容", Command.ITEM,1);
static final Command cmdCaretPosition =
new Command("獲得脫字符號(hào)位置", Command.ITEM,1);
static final Command cmdSize =
new Command("文本大小", Command.ITEM,1);
static final Command cmdExit = new Command("退出", Command.STOP, 2);
int count = 0;
public void startApp() {
//設(shè)置Displayable對(duì)象
tb.addCommand(cmdExit);
tb.addCommand(cmdReplaceLast);
tb.addCommand(cmdInsertFirst);
tb.addCommand(cmdDeleteBeforeChar);
tb.addCommand(cmdDeleteAfterChar);
tb.addCommand(cmdCaretPosition);
tb.addCommand(cmdSize);
tb.addCommand(cmdGetString);
tb.setCommandListener(this);
//顯示滾動(dòng)條
tb.setTicker(ticker);
display = Display.getDisplay(this); //獲得當(dāng)前MIDlet的Display對(duì)象
display.setCurrent(tb); //設(shè)置tb對(duì)象為當(dāng)前顯示對(duì)象
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
/**
* 處理命令按鈕事件
*/
public void commandAction(Command c, Displayable d) {
String label = c.getLabel();
if (label.equals("退出")) {
destroyApp(true);
} else if(label.equals("在開(kāi)始插入")) {
//在當(dāng)前位置插入一個(gè)數(shù)字
String str = Integer.toString(count++);
tb.insert(str, 0);
} else if(label.equals("替換")) {
//替換最后的字符
String str = Integer.toString(count++);
tb.setChars(str.toCharArray(), 0, str.length());
}else if(label.equals("刪除第一個(gè)字符")) {
//刪除第一個(gè)字符
int size = tb.size();
if (size>0) {
//當(dāng)沒(méi)有字符時(shí)不能執(zhí)行該功能
tb.delete(0, 1);
}
} else if(label.equals("刪除最后一個(gè)字符")) {
//刪除最后一個(gè)字符
int size = tb.size();
if (size>0) {
//當(dāng)沒(méi)有字符時(shí)不能執(zhí)行該功能
tb.delete(size-1, 1);
}
} else if(label.equals("獲得脫字符號(hào)位置")) {
//在標(biāo)題欄顯示光標(biāo)的位置
tb.setTitle("當(dāng)前脫字符號(hào)位置:" + tb.getCaretPosition());
} else if(label.equals("文字內(nèi)容")) {
//獲得文本框的輸入內(nèi)容
ticker.setString(tb.getString());
} else if(label.equals("文本大小")) {
//在標(biāo)題上顯示文本的大小
tb.setTitle("當(dāng)前文本大小為:" + tb.size());
}
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -