Creating your first app
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
- 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.
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 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.
On the Home screen of the simulator, click the application icon. In this example, click
Hello BlackBerry icon.
The HelloBlackBerry app opens and displays a screen with an editable text field and a button.
- 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
- 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 promted 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.