Tutorial: Hello BlackBerry
The BlackBerry Java Plug-in for Eclipse provides templates you can use to create a basic app. You can customize the code in the template to suit your needs, or you can create an app from scratch with an empty template.
To get you started, we'll create a version of the "Hello World" app with the Hello BlackBerry template. This version of "Hello World" is a basic UI application that provides some simple UI components. The app includes an editable text field that allows the smartphone user to type text in a field; in this example, they can type their name. The app also includes a button field. When the smartphone user types their name and clicks the Say Hello to button, the app displays a dialog box with the text Hello <username> as shown in the following screenshot.
Create the Hello BlackBerry app
In the BlackBerry Java Plug-in for Eclipse, make sure you turn on the BlackBerry Application Development perspective. Click Window > Open Perspective > Other and then choose BlackBerry Application Development
- From the BlackBerry menu, click New > BlackBerry Project.
- In the Project name field, type HelloBlackBerry.
- In the New BlackBerry Project dialog, select Create new project in workspace.
- Under JRE, select Use a project specific JRE and then choose BlackBerry JRE 7.0.0 from the dropdown list.
- Click Next.
- Click Next.
- Select the Hello BlackBerry template.
- Click Finish.
In the list of projects in the Package Explorer pane, the HelloBlackBerry project appears. You can expand the project to see that the src/mypackage folder contains two Java source files:
- HelloBlackBerry.java: This file contains the source code for the main section of the app.
- HelloBlackBerryScreen.java: This file contains the source code for generating the screen.
Running your app
You can run and test your app on a BlackBerry Smartphone Simulator or a BlackBerry smartphone.
The BlackBerry Java Plug-in for Eclipse includes simulators for various BlackBerry smartphone models. The simulators run the same Java code as the smartphones, so a simulator provides an accurate environment for testing how your app will function on a BlackBerry device.
Run your app in a simulator
In the following steps, we'll use the Hello BlackBerry app that we created earlier to demonstrate how to run an application.
In the Package Explorer pane, select the project you want to run. For this example, select the HelloBlackBerry project.
To run the app in a simulator, perform one of the following actions:
Right-click the project, and then select Run As > BlackBerry Simulator.
If you enabled the BlackBerry Application Development perspective, then from the BlackBerry toolbar, click the Run on BlackBerry Simulator button.
The BlackBerry Java Plug-in for Eclipse builds and packages the project, and then launches the BlackBerry Smartphone Simulator.
On the Home screen of the simulator, click the application icon. In this example, click the Hello BlackBerry icon.
To test the Hello BlackBerry app, type your name in the Enter Name field, and then click the Say Hello to button.
A dialog box displays with the text Hello <your name> and an OK button. Click OK.
To close the app on the simulator, press the Menu key, and then select Close.
To close the simulator, click File > Exit.
Run your app on a smartphone
If your app uses protected Research In Motion APIs, you must first get code signing keys from RIM. For more information about code signing and registering with RIM to use protected APIs, see www.blackberry.com/SignedKeys.
Connect the BlackBerry smartphone to your computer with a USB cable.
In the Eclipse Package Explorer pane, right-click the project that you want to load on the device.
Click BlackBerry > Load Project(s) on Device.
The BlackBerry Java Plug-in for Eclipse builds and packages the project. If the smartphone is password-protected, you are prompted to type the password. The application is loaded on to the device.
On the Home screen of the smartphone, click the application icon to run the app.