Help Center

Local Navigation

Create a date field

  1. Import the required classes and interfaces.
    import net.rim.device.api.ui.*; 
    import net.rim.device.api.ui.component.*; 
    import net.rim.device.api.ui.container.*;
    import java.lang.*;
  2. Create the application framework by extending the UiApplication class. In main(), create an instance of the new class and invoke enterEventDispatcher() to enable the application to receive events. In the application constructor, invoke pushScreen() to display the custom screen for the application. The MyUiScreen class, which is described in step 3, represents the custom screen.
    public class MyUi extends UiApplication
    {
        public static void main(String[] args) 
        { 
            MyUi theApp = new MyUi();
            theApp.enterEventDispatcher();
        } 
        public MyUi()
        { 
            pushScreen(new MyUiScreen());
        }
    }
  3. Create the custom screen for the application by extending the MainScreen class. In the screen constructor, invoke setTitle() to specify the title for the screen.
    class MyUiScreen extends MainScreen 
    {
        public MyUiScreen()
        {
            setTitle("UI Component Sample");
        }
    }
  4. In the screen constructor, create a date field by using the DateField class. Provide System.currentTimeMillis() as a parameter to return the current time. Use the DateField.DATE_TIME style to display both the date and the time. You can use other styles to display only the date or only the time.
    add(new DateField("Date: ", System.currentTimeMillis(), DateField.DATE_TIME));

Was this information helpful? Send us your comments.