Wednesday, July 22, 2009

HelloWorld in BlackBerry

Before starting anything its became a tradition to start with HelloWorld.
Here list of HelloWorld programming in 200 different languages.

So to maintain the tradition we are going to write helloWorld in BlackBerry. :)

1. Open the JDE

2. Create a new workspace (File -> New -> Workspaces) and name it as helloWorld .

3. Create a new Project under the helloWorld workspace
File -> New -> Projects or
Right click on the helloWorld.jdw (on the left side of the JDE) and click 'Create new Project in
helloWorld.jdw ...' and name it as helloWorld.

4. Now create a file under the helloWorld project.
Right click on the helloWorld.jdp and click 'Create new File in
Project ...' and name it as HelloWorld.java

5. Paste the following in the HelloWorld.java file.




import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

class HelloWorld extends UiApplication
{
public HelloWorld()
{
super();

/// creating mainScreen to diaply hellowrld
MainScreen helloWorldScreen = new MainScreen();
LabelField lbl = new LabelField("Hello World");
helloWorldScreen.add(lbl);

//pushing that screen to Display
this.pushScreen(helloWorldScreen);
}

public static void main(String[] args)
{
HelloWorld helloWorld = new HelloWorld();
helloWorld.enterEventDispatcher();
}
}


6. Now build and Run the project (Build -> Build All and Run)

7. Go to the home screen of the simulator and click the application named helloWorld.

8. Enjoy HelloWorld in the BB Simulator.

3 comments: