import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class DemoTextBox extends MIDlet
implements CommandListener {
private Display display;
private TextBox tb;
private Form formInfo;
private Alert alert;
private Command cmdKeluar;
private Command cmdSetTeks;
private Command cmdSisipTeks;
private Command cmdKosongkanTeks;
private Command cmdInfoTeks;
private Command cmdKembali;
public DemoTextBox() {
display = Display.getDisplay(this);
tb = new TextBox("Contoh TextBox", null,
256, TextField.ANY);
cmdKeluar = new Command("Keluar", Command.EXIT, 1);
cmdSetTeks = new Command("Set Teks", Command.SCREEN, 2);
cmdSisipTeks = new Command("Sisipkan Teks",
Command.SCREEN, 2);
cmdKosongkanTeks = new Command("Kosongkan Teks",
Command.SCREEN, 2);
cmdInfoTeks = new Command("Info Teks", Command.SCREEN, 2);
cmdKembali = new Command("Kembali", Command.SCREEN, 2);
tb.addCommand(cmdKeluar);
tb.addCommand(cmdSetTeks);
tb.addCommand(cmdSisipTeks);
tb.addCommand(cmdKosongkanTeks);
tb.addCommand(cmdInfoTeks);
tb.setCommandListener(this);
}
public void startApp() {
display.setCurrent(tb);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(true);
notifyDestroyed();
} else if (c == cmdSetTeks) {
tb.setString("Contoh pengesetan teks di dalam TextBox");
} else if (c == cmdSisipTeks) {
tb.insert("TEKS SISIPAN", 0);
} else if (c == cmdKosongkanTeks) {
if (tb.size() > 0) {
tb.delete(0, tb.size());
}
} else if (c == cmdInfoTeks) {
formInfo = new Form("Informasi Teks");
formInfo.append("Teks aktif: " + tb.getString() + "\n");
formInfo.append("Jumlah karakter: " + tb.size() + "\n");
formInfo.append("Posisi cursor: " + tb.getCaretPosition());
formInfo.addCommand(cmdKembali);
formInfo.setCommandListener(this);
display.setCurrent(formInfo);
} else if (c == cmdKembali) {
display.setCurrent(tb);
}
}
}
No comments:
Post a Comment