DateField sample program in J2ME

By: Jagan Emailed: 1645 times Printed: 2114 times    

Latest comments
By: rohit kumar - how this program is work
By: Kirti - Hi..thx for the hadoop in
By: Spijker - I have altered the code a
By: ali mohammed - why we use the java in ne
By: ali mohammed - why we use the java in ne
By: mizhelle - when I exported the data
By: raul - no output as well, i'm ge
By: Rajesh - thanx very much...
By: Suindu De - Suppose we are executing

First of all, notice that DateFieldDemo extends the Form class. The constructor simply adds a
DateField object to the form and the necessary structure is in place. A DateField is simply a text element that displays a date and time. 

When you run this midlet, the first line in the output, "Date/Time in GMT," is the label and is specified in the first argument of the constructor. The second line is the date, and the third line is the time. The DateFieldDemo no-arg constructor in the program above demonstrates how to set the date of the 
DateField object using a java.util.Calendar object.

This example displays the date and time because the constructor call specifies the display of both quantities. The DateField class defines three constants, which let you control what information is displayed.

import java.util.Date;
import java.util.Calendar;
import java.util.TimeZone;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.DateField;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
/**
Demonstrates the use of the MIDP UI DateField class.
@see javax.microedition.lcdui.DateField
*/
public class DateFieldDemo extends Form
implements CommandListener
{
private Command back = new Command("Back", Command.BACK, 1);
private static Displayable instance;
private DateField date =
new DateField("Date/Time in GMT",
DateField.DATE_TIME,
TimeZone.getDefault());
/**
Constructor.
*/
public DateFieldDemo()
{
super("DateField Demo");
Calendar cal = Calendar.getInstance();
date.setDate(cal.getTime());
append(date);
addCommand(back);
setCommandListener(this);
instance = this;
}
/**
Returns the single instance of this class. Calling
this method before constructing an object will return
a null pointer.
@return an instance of this class.
*/
public static Displayable getInstance()
{
return instance;
}
public void commandAction(Command c, Displayable d)
{
if (c == back)
{
UIComponentDemo.getInstance().display();
}
 

}
}

The third DateField constructor argument is the time zone specification, which is a java.util.TimeZone object. Beware of the fact that the MIDP specification requires implementations to support only one time zone. You should be aware of what time zones your implementation supports. It's quite possible that most MIDP implementations will only support one time zone.

A DateField constructor call can specify a time zone that is not supported by your MIDP implementation. If the time zone you specify in the constructor is not supported by your MIDP implementation, your program will still execute without error or warning, but the DateField object's time zone will represent whatever time zone is supported by the implementation, not the one you requested. And the time displayed on screen will reflect the time zone used by the DateField object instead of the time zone you specified in the constructor call.

DateField objects are editable. To edit them,

1. First, select the date field.
2. Click the Select button. You'll see the display change.
3. Scroll up and down to highlight the year, month, or day, and change each as desired.

Notice that the implementation has placed a Back soft button and a Save soft button on the display.
This interface presentation is typical of all editable components. When you finish editing and revert to the previous screen, the displayed date and time will have changed.


J2ME Home | All J2ME Tutorials | Latest J2ME Tutorials

Sponsored Links

If this tutorial doesn't answer your question, or you have a specific question, just ask an expert here. Post your question to get a direct answer.



Bookmark and Share

Comments(0)


Be the first one to add a comment

Your name (required):


Your email(required, will not be shown to the public):


Your sites URL (optional):


Your comments:



More Tutorials by Jagan
Importing a Certificate for the CA example using keytool in Java
The if-then-else Statement in Java
WHERE Clauses in SQL
The TryCatchFinally Interface in JSP
assert() Function Example program in C
Guidelines for Struts Application Development
Using printf function in C
File Inclusion in C
Using Multiple Message Resource Bundles in Struts
While and For Loops in C
Arrays sample program in C
Controlling Page Navigation in JSF - Static and Dynamic Navigation
Using cout.fill() in C++
Types of Profiles in J2ME
DateField sample program in J2ME

More Tutorials in J2ME
Code sample to Send SMS from a J2ME application.
Adding your own Application icon for your J2ME application (jar file)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Datagrams in J2ME (UDP Programming sample)
Client Server in J2ME (Socket Programming sample)
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Using HTTP vs UDP vs Socket in J2ME
RMSCookieConnector - Using Cookies in J2ME
POST UTF-8 encoded data to the server in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
Using List to create a Menu and Menu items in J2ME
Using alerts and tickers in J2ME
J2ME Canvas sample to show games programming in J2ME
Timer and TimerTask example in J2ME
List of GPRS Access points for all countries

More Latest News
Most Viewed Articles (in J2ME )
paint() sample program to draw a line in J2ME
lists, forms, choices, gauges, text fields, text boxes in J2ME
A sample J2ME midlet that shows an example of using a Timer and a TimerTask.
Client Server in J2ME (Socket Programming sample)
Sample Java program shows how to Read a file over a network using J2ME midlet
Image and ImageItem sample program in J2ME
Types of Profiles in J2ME
Datagrams in J2ME (UDP Programming sample)
What is J2ME?
Download a file over a network in J2ME midlet
Using HttpConnection in J2ME (Retrieve web content from a website to a phone)
Play a multimedia file in J2ME Program (Audio/Video) using MMAPI
Code sample to Send SMS from a J2ME application.
'LINK.EXE' is not recognized as an internal or ext
Sample J2ME code that shows various functionality of RMS.
Most Emailed Articles (in J2ME)
Download a file over a network in J2ME midlet
How to load J2ME applications to the IDEN handsets
POST UTF-8 encoded data to the server in J2ME
What is J2ME?
Adding your own Application icon for your J2ME application (jar file)
Y.S. Sun Green Building Research Center
A sample J2ME midlet that shows an example of using a Timer and a TimerTask.
paint() sample program to draw a line in J2ME
translate() Sample program in J2ME
RMS Basics in J2ME
What is J2ME?
Sample Java program shows how to Read a file over a network using J2ME midlet
DateField sample program in J2ME
Sample program to draw a rectangle in J2ME
Sample program to draw a arc in J2ME