Monday, February 13, 2012

Blackberry Application Helloworld.

This tutorial is help you write a simple blackberry device hello world application. That's help you to getting start to developed blackberry application. Here i assume is that we have already install eclipse for blackberry. if you have not install blackberry eclipse please follow this step. Please follow following step.

1. Open Eclipse and create a new blackberry project.
2. Create Project name Helloworld and press next.
3. You will see "src" and "res" folder on this screen please press next button
4. Select "Blackberry Application" template and press next.
5. Specify package and class name of application in this step.
Create new package name "com.bbdevelopement.helloworld"
Write application class name. This is our blackberry application starting point.
Specify application Screen class. This is application screen we can add TextField, Button etc.
Screen Title: Title of main screen.
After completed this step you can see that following code are display on MainApplication In the class extend it from net.rim.device.api.ui.UiApplication, this would be our main entry point for application and contain main method the source code is as follows:
package com.bbdevelopement.helloworld;

import net.rim.device.api.ui.UiApplication;

/**
 * This class extends the UiApplication class, providing a
 * graphical user interface.
 */
public class MainApplication extends UiApplication
{
    /**
     * Entry point for application
     * @param args Command line arguments (not used)
     */ 
    public static void main(String[] args)
    {
        // Create a new instance of the application and make the currently
        // running thread the application's event dispatch thread.
        MainApplication theApp = new MainApplication();       
        theApp.enterEventDispatcher();
    }
    

    /**
     * Creates a new MainApplication object
     */
    public MainApplication()
    {        
        // Push a screen onto the UI stack for rendering.
        pushScreen(new StartScreen());
    }    
}

The main method is called at first by blackberry OS which makes a new instance of our application and dispatch it, in the constructor we create an instance of HelloWorldScreen and push it on the application stack.

package com.bbdevelopement.helloworld;

import net.rim.device.api.ui.container.MainScreen;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class StartScreen extends MainScreen
{
    /**
     * Creates a new StartScreen object
     */
    public StartScreen()
    {        
        // Set the displayed title of the screen       
        setTitle("Helloworld");
    }
}


You have just made your first blackberry application, you can run and test this application in simulator, it would show following screen.





No comments:

Post a Comment