Display a label at an absolute position on the screen

  1. Import the required classes and interfaces.
    import net.rim.device.api.system.*;
    import net.rim.device.api.ui.*; 
    import net.rim.device.api.ui.container.*;
    import net.rim.device.api.ui.component.*;
  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 AbsoluteFieldManagerDemoScreen class, described in step 3, represents the custom screen.
    public class AbsoluteFieldManagerDemo extends UiApplication
    {
         public static void main(String[] args)
         {
             AbsoluteFieldManagerDemo app = new AbsoluteFieldManagerDemo();
             app.enterEventDispatcher();
         }
        
         public AbsoluteFieldManagerDemo()
         {
            	pushScreen(new AbsoluteFieldManagerDemoScreen());
         }
    }
  3. Create the framework for the custom screen by extending the MainScreen class. Invoke setTitle() to specify the text that appears in the title section of the screen.
    class AbsoluteFieldManagerDemoScreen extends MainScreen
    {	
         public AbsoluteFieldManagerDemoScreen()
         {
              setTitle("AbsoluteFieldManager Demo");
         }
    }
  4. In the screen constructor, create an instance of the AbsoluteFieldManager class.
    AbsoluteFieldManager manager = new AbsoluteFieldManager();
  5. In the screen constructor, create and initialize a variable to store the y co-ordinate that corresponds to the vertical center of the screen.
    int halfwayDown = Display.getHeight() / 2;
  6. In the screen constructor, invoke AbsoluteFieldManager.add() to add a LabelField object at the vertical center of the screen and with an x co-ordinate of 2.
    manager.add(new LabelField("Hello world"), 2, halfwayDown);
  7. In the screen constructor, invoke add() to add the AbsoluteFieldManager to the screen.
    add(manager);

Was this information helpful? Send us your comments.