Java by API/javax.microedition.lcdui/DateField — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
м (1 версия)
 
м (1 версия)
 
(нет различий)

Текущая версия на 14:49, 31 мая 2010

DateField.DATE_TIME

 
import java.util.Calendar;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
public class DateFieldDATE_TIME extends MIDlet {
  protected Display display;
  protected void startApp() {
    display = Display.getDisplay(this);
    Form form = new Form("Demo");
    form.append("line");
    DateField timeOnly = new DateField("Time", DateField.DATE_TIME);
    timeOnly.setDate(Calendar.getInstance().getTime());
    form.append(timeOnly);
    display.setCurrent(form);
  }
  protected void pauseApp() {
  }
  protected void destroyApp(boolean unconditional) {
  }
}





DateField(String label, int mode)

 
import java.util.Calendar;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
public class DateFieldTIME extends MIDlet {
  protected Display display;
  protected void startApp() {
    display = Display.getDisplay(this);
    Form form = new Form("Demo");
    form.append("line");
    DateField timeOnly = new DateField("Time", DateField.TIME);
    timeOnly.setDate(Calendar.getInstance().getTime());
    form.append(timeOnly);
    display.setCurrent(form);
  }
  protected void pauseApp() {
  }
  protected void destroyApp(boolean unconditional) {
  }
}





DateField.TIME

 

import javax.microedition.lcdui.rumand;
import javax.microedition.lcdui.rumandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.midlet.MIDlet;
public class DateFieldMIDlet extends MIDlet implements CommandListener {
  private Command exitCommand;
  private DateField dateDateField = new DateField("date:", DateField.DATE);
  private DateField timeDateField = new DateField("time:", DateField.TIME);
  private DateField bothDateField = new DateField("both:", DateField.DATE_TIME);
  private Display display;
  public DateFieldMIDlet() {
    display = Display.getDisplay(this);
    exitCommand = new Command("exit", Command.EXIT, 1);
    java.util.Date now = new java.util.Date();
    dateDateField.setDate(now);
    timeDateField.setDate(now);
    bothDateField.setDate(now);
  }
  public void startApp() {
    Form aForm = new Form("DateField");
    aForm.append(dateDateField);
    aForm.append(timeDateField);
    aForm.append(bothDateField);
    aForm.addCommand(exitCommand);
    aForm.setCommandListener(this);
    display.setCurrent(aForm);
  }
  public void pauseApp() {
  }
  public void destroyApp(boolean unconditional) {
  }
  public void commandAction(Command c, Displayable s) {
    if (c == exitCommand) {
      destroyApp(false);
      notifyDestroyed();
    }
  }
}