import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class ContohTicker5 extends MIDlet
implements CommandListener {
private Display display;
private Form form;
private Ticker ticker;
private StringItem si;
private static final long SLEEP_TIME = 40000;
private boolean isIklanPertama;
private String teksTickerPertama = "Pesan atau informasi ke-1";
private String teksTickerKedua = "Pesan atau informasi ke-2";
private String isiLayar =
"Pada aplikasi ini kita dapat mengubah isi ticker " +
"secara dinamis";
private final Command cmdKeluar =
new Command("Keluar", Command.EXIT, 1);
public ContohTicker5() {
display = Display.getDisplay(this);
}
public void startApp() {
PenggantiIsiTicker thread = new PenggantiIsiTicker();
thread.start();
form = new Form("Contoh Ticker ke-5");
ticker = new Ticker(teksTickerPertama);
form.setTicker(ticker);
si = new StringItem(null, isiLayar);
form.append(si);
form.addCommand(cmdKeluar);
form.setCommandListener(this);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
notifyDestroyed();
}
}
// inner class
class PenggantiIsiTicker extends Thread {
public void PenggantiIsiTicker() {
}
public void run() {
while (true) {
try {
Thread.sleep(SLEEP_TIME);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
if (isIklanPertama) {
isIklanPertama = false;
ticker.setString(teksTickerPertama);
} else {
ticker.setString(teksTickerKedua);
isIklanPertama = true;
}
}
}
}
}
No comments:
Post a Comment