BlackBerry Programming
The Blackberry platform is Java® based, and there are number of different tools that you can
use to develop your applications. This tutorials only show basic programming for Blackberry® application. We assume that you’re not beginner in programming. Java® language is mandatory. This tutorials use Windows® OS, but you may develop use other OS.
Tools:
use to develop your applications. This tutorials only show basic programming for Blackberry® application. We assume that you’re not beginner in programming. Java® language is mandatory. This tutorials use Windows® OS, but you may develop use other OS.
Tools:
- Java® SE Development Kit (JDK)
You can use version 5 or version 6. Version 6 is required if you are using BlackBerry® MDS-CS for debugging. - Eclipse® IDE for Java® Developers
The essential tools for any Java® developer, including a Java® IDE, a CVS client, XML Editor and Mylyn. - BlackBerry® Java® Development Environment (JDEs)
The BlackBerry® Java® Development Environment (BlackBerry JDE) is a fully integrated development environment and simulation tool for building Java Platform, Micro Edition (Java® ME) applications for Java® based BlackBerry® smartphones.
It is a Mobile Information Device Profile (MIDP) compliant Java® ME environment for developers who wish to maintain seamless portability in their wireless applications. In addition, the BlackBerry® JDE provides a full suite of interfaces and utilities to take advantage of some of the unique features of the BlackBerry smartphone. - BlackBerry® Eclipse™ Plug-in
The BlackBerry® Web Development Plug-in for Eclipse™ allows developers to debug web-based applications and content for the BlackBerry solution.
Working through the familiarity of Eclipse™ allows simplified code profiling and increases overall efficiencies. Users enjoy seamless integration with Eclipse™ 3.4, which allows comprehensive development of BlackBerry web applications and contents.
The BlackBerry® Web Development Plug-in for Eclipse also facilitates active web development and debugging with a BlackBerry® Smartphone Simulator as well as active web profiling to optimize web projects.
Steps:
- Download JDK and Eclipse IDE for Java®.
All the tools are absolutely free. - Install Java® SE Development Kit (JDK)
- Install Eclipse™ IDE for Java® Developers
- Seting up Eclipse
- Setup JDE Plug-in for Eclipse™ update site
- From the Help menu, select Software Updates… to open the Software Updates and Add-ons window
- Select the Available Software tab
- Click the Add Site… button
- In the Add Site dialog, type the URL http://www.blackberry.com/go/eclipseUpdate into the location text box
- Click the OK button, BlackBerry Update Site appears in the Available Software list
- Select the BlackBerry JDE Plug-in for Eclipse item and one BlackBerry Component Pack item you want to work on
- Click the Install… button
- Click the Next > button
- Check I accept the terms of the license agreement radio button after reviewing licenses
- Click the Finish button to begin installation
Note: You’ll need to enter your BlackBerry® Developer Zone login ID and password in an authentication dialog. Due to security policy, you may be authenticated multiple times. If you don’t have a Developer Zone login, register for access to the BlackBerry Developer Community - After successfully downloading the files, you’ll be prompted to restart the Eclipse Platform. Choose to restart the platform
- Further Reference: BlackBerry® JDE Plug-in for Eclipse™ Installation and Configuration by Mike Kirkup
- Setup JDE Plug-in for Eclipse™ update site
- Write the code with Java® Languange
- Setup New Project
- Click on File/New/Project menu
- Select BlackBerry/Blackberry Project
- Click Next
- Chose Project name and location
- Enter the project name, i.e. “Hello World“
- Select your location or use a default one to store your project
- Click Finish
- Configure your new BlackBerry project
- Click on BlackBerry/Configure Blackberry Workspace
- Click on the BlackBerry Workspace and insert your Vendor and Version data
- Here you can change a number of different settings. Let’s just enter version number 1.0 and
vendor “TestVendor” - From BlackBerry JDE, select Installed Components
- Chose component package – 4.6.0 (Figure 6)
- Click OK
- Create a new HelloWorld Class
- Click on File/New/Package
- Enter the package path i.e. com.rim.samples.helloworld
- Click on Finish button
- Click on File/New/Class
- Check the source folder and package. It should be Hello World/src and com.rim.samples.helloworld respectively
- Enter HelloWorld as the name and click Finish
- Implement a UiApplication
- Type extends UiApplication after public class HelloWorld
- Import the net.rim.device.api.ui by click on light bulb icon with red cross or by typing import net.rim.device.api.ui.UiApplication;
- Create Method on Class HelloWorld
public static void main(String[] args) {
HelloWorld theApp = new HelloWorld();
theApp.enterEventDispatcher();
} - Create New Screen Object and Display it in the constructor
public HelloWorld() {
//display a new screen
pushScreen(new HelloWorldScreen());
}
- Create HelloWorldScreen Class
- add a HelloWorldScreen class which extends MainScreen:
final class HelloWorldScreen extends MainScreen - Import net.rim.device.api.ui.container.MainScreen:
import net.rim.device.api.ui.container.MainScreen;
You can type the line or click on light bulb icon as described before - In the constructor of this class we will create LabelField title, to label our
Application. Set the title and add a RichTextField with our message “Hello World!”. We also
need to remember to import necessary packages as well as call MainScreen’s constructor - Import net.rim.device.api.ui.component.LabelField
- Import net.rim.device.api.ui.component.RichTextField
- add a small dialog which will appear when the user wants to exit the application. To
do so we need to overwrite the onClose() method of the HelloWorldScreen class - Import net.rim.device.api.ui.component.Dialog
- Import net.rim.device.api.ui.component.*
- Final Source Code
package com.rim.samples.helloworld;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.MainScreen;
public class HelloWorld extends UiApplication {
public static void main(String[] args) {
HelloWorld theApp = new HelloWorld();
theApp.enterEventDispatcher();
}
public HelloWorld() {
pushScreen(new HelloWorldScreen());
}
}
final class HelloWorldScreen extends MainScreen {
public HelloWorldScreen() {
super();
LabelField title = new LabelField(“HelloWorld Sample”,
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);
add(new RichTextField(“Hello World!”));
}
public boolean onClose() {
Dialog.alert(“Goodbye!”);
System.exit(0);
return true;
}
}
- add a HelloWorldScreen class which extends MainScreen:
- Setup New Project
- Build and Run…
- Click on Run/Run or the green shortcut icon on the toolbar
- You can also choose to click Run/Debug, which will allow you to debug your application, but it also takes longer to load
- When you get the simulator find and start your application from Downloads folder
- When you run the application you should see our Hello World message
- And when you click on exit button you will get the “Goodbye” dialog
- To exit the simulator, just close its window
Reference:
Leave a Reply