BlackBerry
Enviado por pachita.25 • 8 de Junio de 2013 • 1.397 Palabras (6 Páginas) • 192 Visitas
Page | 1
A10 – Writing Your First Application
for BlackBerry

Page | 2
Contents
A10 – Writing Your First Application .........................................................................................................3 Introduction.............................................................................................................................................4 Development ...........................................................................................................................................5 Setting up New BlackBerry Project ...................................................................................................................... 5 Configuring Your New BlackBerry Project ........................................................................................................... 7 Creating HelloWorld Class ................................................................................................................................... 9 UiApplication ..................................................................................................................................................... 11 MainScreen ........................................................................................................................................................ 14 Running Application in the Simulator ................................................................................................................ 16 Other Variations.....................................................................................................................................18 Links ......................................................................................................................................................19

Page | 3
A10 – Writing Your First Application
This tutorial will show you how to write a basic application for BlackBerry devices. The application will display the simple “Hello World” message on the screen.
To be able to do so it is required to have the following installed on your system:
• Sun JDK
• Eclipse SDK,
• BlackBerry JDE Plug-in for Eclipse and
• BlackBerry JDE Component Packs 4.3 – 4.7
If you need help setting up please look at A1 – Setting up Tools tutorial.
If you are ready, launch the Eclipse, and go to your Workbench (Figure 1).
Figure 1

Page | 4
Introduction
In this tutorial I will show you the following:
• How to setup and configure new BlackBerry project,
• How to create classes,
• Some details about UiApplication and MainScreen,
• How to write a Hello World application and
• How to run your application in simulator.
Please note that you can always find more information about the APIs we are using in BlackBerry API reference document, which is the part of any JDE Component Pack (Figure 2). You can find it on your computer under Start / Programs / Research in Motion / BlackBerry JDE 4.x.
Figure 2

Page | 5
Development
Setting up New BlackBerry Project
To setup your new BlackBerry project:
1. Click on File/New/Project menu.
2. Select BlackBerry project (Figure 3).
Figure 3
3. Click Next.
4. Chose Project name and location (Figure 4).

Page | 6
Figure 4
5. Enter the project name, i.e. “Hello World“.
6. Select your location or use a default one to store your project.
7. Click Finish.

Page | 7
Configuring Your New BlackBerry Project
To configure your new BlackBerry project:
1. Click on BlackBerry/Configure Blackberry Workspace.
2. Click on the BlackBerry Workspace and insert your Vendor and Version data (Figure 5).
Figure 5
3. Here you can change a number of different settings. Let’s just enter version number 1.0 and vendor “TestVendor”.
4. From BlackBerry JDE, select Installed Components

Page | 8
Figure 6
5. Chose component package – 4.6.0 (Figure 6).
6. Click OK.

Page | 9
Creating HelloWorld Class
To start developing our application after setting up and configuring our Workspace, we need to create a new HelloWorld Class:
1. Click on File/New/Package (Figure 7).
2. Enter the package path i.e. com.rim.samples.helloworld.
3. Click on Finish button.
4. Click on File/New/Class (Figure 8)
Figure 7

Page | 10
Figure 8
5. Check the source folder and package. It should be Hello World/src and com.rim.samples.helloworld respectively.
6. Enter HelloWorld as the name and click Finish.

Page | 11
UiApplication
Any BlackBerry application that provides a user interface must extend the UiApplication class.
A UI application maintains a stack of Screen objects. As it pushes screens onto the stack, it draws them on top of any other screens already on the stack. When the application pops a screen off the stack, it redraws the underlying screens as necessary. Only the screen on the top of the stack receives input events.
To implement a UiApplication, the HelloWorld class we just created must extend the UiApplication class:
1. Type extends UiApplication after public class HelloWorld (Figure 9).
2. We need to import the net.rim.device.api.ui package. To the left of the public class HelloWorld line is a light bulb icon with red cross. Click on it and then click on Import ‘UiApplication’ (Figure 10).
3. Youcanalsotype:
import net.rim.device.api.ui.UiApplication;
but the above approach saves you a bit of time.
Figure 9

Page | 12
Figure 10
4. ClassHelloWorldmusthaveonemethod:
• main(String[] args) which is the entry point into our application. We need to create an instance of our application and start it by getting it
...