import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.Calendar;
import java.util.TimeZone;
import java.util.Date;
public class DemoItemStateListener extends MIDlet
implements CommandListener {
private Display display;
private Form form;
private final Command cmdKeluar =
new Command("Keluar", Command.EXIT, 1);
public DemoItemStateListener() {
display = Display.getDisplay(this);
form = new Form("Demo ItemStateListener");
form.addCommand(cmdKeluar);
form.setCommandListener(this);
}
public void startApp() {
ItemStateListener listener = new ItemStateListener() {
Calendar cal =
Calendar.getInstance(TimeZone.getDefault());
public void itemStateChanged(Item item) {
cal.setTime(((DateField) item).getDate());
Alert alert = new Alert("Informasi", null, null,
AlertType.INFO);
alert.setTimeout(3000);
alert.setString("Tanggal telah berhasil diubah.");
display.setCurrent(alert, form);
}
};
form.setItemStateListener(listener);
Date now = new Date();
DateField dateItem = new DateField("Hari ini tanggal: ",
DateField.DATE);
dateItem.setDate(now);
form.append(dateItem);
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command c, Displayable s) {
if (c == cmdKeluar) {
destroyApp(false);
notifyDestroyed();
}
}
}
No comments:
Post a Comment