Date Field Midlet Example

This example illustrates how to insert date field in your form.

Date Field Midlet Example

Date Field MIDlet Example

     

This example illustrates how to insert date field in your form. We are using here two fields DateField (datein and dateout) and initialize a final static variable DATE which is 0. We are taking both DateField variable in to the constructor (DateFieldExample). When application will run, first of all the startApp() method will be called and it will display the form with datein and dateout field. For the specific date we are using here java.util.Date class and java.util.TimeZone class is used to show the format of date like in figure Tue, 30 Sep, 2008

Application display as follows:

When <date> is selected, a new window will open with a calendar as given below.

and you can select your choice of date, month and year which will appear on the form as follows. 

 

The source code of the DateFieldExample.java is as follows:  

import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.Date;
import java.util.TimeZone;

public class DateFieldExample extends MIDlet{
  private Form form;
  private Display display;
  private DateField datein, dateout;  
  private static final int DATE = 0;

  public DateFieldExample(){
  datein = new DateField("Date In:", DateField.DATE, TimeZone.getTimeZone("GMT"));
  dateout = new DateField("Date Out:", DateField.DATE, TimeZone.getTimeZone("GMT"));
  }

  public void startApp(){
  display = Display.getDisplay(this);
  Form form = new Form("Date Field");
  form.append(datein);
  form.append(dateout);
  display.setCurrent(form);
  }

  public void pauseApp(){
  
  }

  public void destroyApp(boolean destroy){
  notifyDestroyed();
  }
}
<> 

Download Source Code