Funding for 'IT Lab' Project, Phase 1: Progress of sticker sales. Purchase a sticker to help us reach our target.Updated: 2010-02-28 11:53
10.7%
J2ME Lesson (5)

By Manoj Alwis


Hi friends,

This month J2ME Lesson 5 illustrate how to insert date field in your form. Upto now I think you know how to create MIDP project in NetBeans IDE,in my first lesson I explained how to create project using Netbeans IDE. In today’s Lesson, first I will create MIDP project in NetBeans by the name CalenderExample. Then I will use two Date Fields (datein and dateout) and initialize a final variable DATE which is 0.And I will take both Date Field variable into the constructor (CalenderExample). When the application runs, first of all the startApp() method will be called and it will display the form with datein and dateout field. For the specific date I will use here java.util.Date class and java.util.Timezone class is used to show the format of the date like figure Sun, 23 Aug,2009.

 When you run the program first Application display as shown below:


Then you launch the application it will display as shown below,

When <date> is selected, a new window will open with a calendar as shown 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 CalenderExample.java is as follows: 

// by Manoj Alwis

import javax.microedition.lcdui.*;

import javax.microedition.midlet.MIDlet;

import java.util.Date;

import java.util.TimeZone;

public class CalenderExample 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();

  }

}



       


Previous Article

Thank you.

wish you good luck, and keep it up buddy.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options