By: Jagan Printer Friendly Format
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.
Demonstrates the use of the MIDP UI DateField class.
public class DateFieldDemo extends Form
private Command back = new Command("Back", Command.BACK, 1);
private static Displayable instance;
private DateField date =
new DateField("Date/Time in GMT",
Calendar cal = Calendar.getInstance();
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()
public void commandAction(Command c, Displayable d)
if (c == back)
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.
Most Viewed Articles (in J2ME )
Latest Articles (in J2ME)
Comment on this tutorial
- Data Science
- Cloud Computing
- Java Beans
- Mac OS X
- Office 365
- Tech Reviews