{"id":467,"date":"2009-10-17T21:07:52","date_gmt":"2009-10-17T21:07:52","guid":{"rendered":"http:\/\/aasims.wordpress.com\/?p=467"},"modified":"2025-04-29T17:36:00","modified_gmt":"2025-04-29T17:36:00","slug":"blackberry-application-development-tutorial-part-3","status":"publish","type":"post","link":"https:\/\/aasimnaseem.com\/blog\/blackberry-application-development-tutorial-part-3\/","title":{"rendered":"BlackBerry Application Development Tutorial (Part-3)"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright\" src=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/09\/bbec.jpg?w=199&amp;h=173\" alt=\"\" width=\"199\" height=\"173\" \/>Hello All;<\/p>\n<p>I wish you receive this post in the best of everything.<\/p>\n<p>This is the 3rd part of the BlackBerry Application Development Tutorial series.\u00a0 First of all, accept my apology for posting this post so late. I was busy with some other projects, and hence couldn&#8217;t find enough time to compose it. I delayed this task for this weekend, and now it&#8217;s ready for you.<br \/>\n<!--more--><br \/>\n<strong>Note:<\/strong> This tutorial is a part of a series of my tutorials on BlackBerry application development; so far we have discussed the following.<\/p>\n<ul>\n<li><a href=\"https:\/\/aasimnaseem.com\/index.php\/2009\/09\/22\/blackberry-application-development-introduction\/\">Introduction :: BlackBerry Application Development<\/a><\/li>\n<li><a title=\"BlackBerry Application Development Tutorial\u00a0(Part-2)\" href=\"https:\/\/aasimnaseem.com\/index.php\/2009\/09\/23\/blackberry-application-development-tutorial-part-2\/\">Setting Up Your System :: BlackBerry Application Development Tutorial\u00a0(Part-2)<\/a><\/li>\n<li><a href=\"https:\/\/aasimnaseem.com\/index.php\/2009\/10\/17\/blackberry-application-development-tutorial-part-3\/\">Your First Application ::\u00a0BlackBerry Application Development Tutorial\u00a0(Part-3)<\/a><\/li>\n<li><a href=\"https:\/\/aasimnaseem.com\/index.php\/2011\/02\/23\/creating-a-webicon-blackberry-application-development-tutorial-part-4\/\">Creating A WebIcon ::\u00a0BlackBerry Application Development Tutorial\u00a0(Part-4)<\/a><\/li>\n<\/ul>\n<p>The pre-request of this tutorial is<a href=\"https:\/\/aasimnaseem.com\/index.php\/2009\/09\/23\/blackberry-application-development-tutorial-part-2\/\"> BlackBerry Application Development Tutorial\u00a0(Part-2)<\/a> for setting your system to start bBlackBerryapplication development.<\/p>\n<p>Before start, I\u2019m assuming that you have configure the Sun JDK, Eclipse SDK, BlackBerry JDE Plug-in for Eclipse and BlackBerry JDE Component Packs successfully on your system \u2026 is that? Kindly confirm again \u2026<\/p>\n<p>Orite, its time to move forward. Bring a cup of coffee, some cookies, play some light song in your favorite music player \u2026. I think some instrumental number will good \u2026<\/p>\n<p>Hmm now you are ready to get start .. .good \u2026 start eclipse and make a new workspace for your blackberry projects.<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-468 aligncenter\" title=\"1\" src=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/10\/1.jpg\" alt=\"1\" width=\"600\" height=\"255\" \/><\/p>\n<p>Alright, next is to create a new project. As you have already installed the JDE plug-in for Eclipse, you will see an entry of \u201cBlackBerry Project\u201d in the Create New Project window.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-470\" title=\"2\" src=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/10\/2.jpg\" alt=\"2\" width=\"334\" height=\"150\" \/><\/p>\n<p>Click next. Chose your project name, but for god sake, don\u2019t use HelloWorld type words&#8230; its time to say good by to Hello World \u2026 do something new, dude \u2026 ummm use \u201c<strong>WelcomeBlackBerry.<\/strong>\u201d Hmm,\u00a0that\u2019s nice \u2026<\/p>\n<p>Chose default location; it will save project in your workspace folder\u2026 Click next and finish.<\/p>\n<p>It&#8217;s better&#8230; in fact, I recommend configuring your project or workspace. Chose configure blackberry workspace and set options like vendor, version, etc.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-475\" title=\"3\" src=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/10\/3.jpg\" alt=\"3\" width=\"501\" height=\"189\" \/><\/p>\n<p>In install component, choose the BlackBerry JDE Component Packs option.<\/p>\n<p>Great. You have set your workspace for BlackBerry applications. Take a sip of coffee and take a bite of cookie. Now its time to learn few concepts \u2026 keep your coffee mug in your hand and concentrate on the following paragraph. Keep taking sips of coffee.<\/p>\n<h2 style=\"font-size: 1.5em;\">PUSH\/POP of Screens<\/h2>\n<p>Every software application has different pages to display different information and components for user interactions like buttons, text fields etc. In BlackBerry applications, we will call them as screens. Mean we will design and develop different screens and will link them via different events like clicking a button will hide one page(screen) and will show other page (screen).<\/p>\n<p>This show\/hide phenomenon in blackberry\u2019s program is called pus and pop of a screen. <strong>Push<\/strong> mean displaying a screen and <strong>Pop <\/strong>means hide it. Its means when we want to display a screen, we first pop top screen and then push that screen we want to show. Hence application is behaving like a stack where we are push and pop screen and maintain a flow of screen as per events triggered by user.<\/p>\n<p>Got the idea? No!!! don\u2019t worry. Read the above paragraph again and when clear move to next one. It\u2019s quite simple han \u2026<\/p>\n<h2>Your First program for BlackBerry<\/h2>\n<p>Now create a new package blackberry and create new Class. Name the new class \u201cFirstBlackBerryClass\u201d<\/p>\n<p>Every class that use user interaction controls must implement a class UiApplication (net.rim.device.api.ui.UiApplication). hey don\u2019t smile .. I know the same class is available in iPhone sdk too, for same purpose \ud83d\ude42<\/p>\n<p>Ok, you have created a class, have implement UiApplication. Now make a main() method to have entry point of the our application. This main method is same as traditional java classes \u2026 yes, you got it. Its our\u00a0public static void main (String[] args)<\/p>\n<p>at this point our class should look like<\/p>\n<p>[code language=&#8221;java&#8221;]<br \/>\npackage com.iainteractive.blackberry;<br \/>\nimport net.rim.device.api.ui.UiApplication;<br \/>\npublic FirstBlackBerryClass extends UiApplication<br \/>\n{<br \/>\npublic static void main(String[] args) { }<br \/>\npublic FirstBlackBerryClass() { }<br \/>\n}<br \/>\n[\/code]<\/p>\n<p>Now in main method, creates an instance\/object of \u00a0your class and calls enterEventDispatcher(), inherited from UiApplication class.\u00a0 This method starts event handling and executes all drawing and event-handling code.\u00a0Now your class should look like<\/p>\n<p>[code language=&#8221;java&#8221;]<br \/>\ncom.iainteractive.blackberry;<br \/>\nimport net.rim.device.api.ui.UiApplication;<br \/>\npublic FirstBlackBerryClass extends UiApplication {<br \/>\npublic static void main(String[] args) {<br \/>\nWelcomeBlackBerry firstApplication&amp;amp;nbsp; = new WelcomeBlackBerry();<br \/>\nfirstApplication.enterEventDispatcher();<br \/>\n}<br \/>\npublic FirstBlackBerryClass(){ }<br \/>\n}<\/p>\n<p>[\/code]<\/p>\n<p>&nbsp;<\/p>\n<p>Our class is read to execute, means at very very basic level you can say you have created your first application.Though it will do nothing. Now its time to add some screen. When our program will run, we should make sure that we have push a screen so that when application start execution, user can see something over his device. To do so, we will first create a screen and then will link it to our main class .i.e. \u00a0FirstBlackBerryClass.<\/p>\n<p>Creating a Screen<\/p>\n<p>Blackberry API provides a class name MainScreen that provides features common to standard RIM device applications like \u00a0a title section, a separator element, and a main scrollable section (actually a single vertical field manager used to maintain a list of fields). So every class that behave like screen or in other words, every screen must extends MainScreen class to get access to different screen sections.\u00a0So our next task is to develop a screen class. Add new class in package, name it as FirstScreen<\/p>\n<p>[code language=&#8221;java&#8221;]<\/p>\n<p>package com.iainteractive.blackberry;<\/p>\n<p>import net.rim.device.api.ui.container.MainScreen;<\/p>\n<p>final class FirstScreen extends MainScreen {<\/p>\n<p>FirstScreen(){<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>[\/code]<\/p>\n<p>Now we will add some element to display. First important thing is title for your application. For this, use LabelField class object and set some string as title. Then set this label as application\u2019s title.<\/p>\n<p>[code language=&#8221;java&#8221;]<\/p>\n<p>LabelField appTitle = new LabelField(&quot;HelloWorld Sample&quot;, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);<\/p>\n<p>this.setTitle(appTitle);<\/p>\n<p>[\/code]<\/p>\n<p>now to add some text over the screen, use RichTextField class and pass some string to display.<\/p>\n<p>[code language=&#8221;java&#8221;]<\/p>\n<p>RichTextField&amp;amp;nbsp; greeting = new RichTextField(&quot;its running\u2026 great&quot;);<\/p>\n<p>[\/code]<\/p>\n<p>Now add it to screen by add() method of MainScreen class.<\/p>\n<p>[code language=&#8221;java&#8221;]<\/p>\n<p>this.add(greeting);<\/p>\n<p>[\/code]<\/p>\n<p>now our FirstScreen class will look like that<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>[code language=&#8221;java&#8221;]<\/p>\n<p>final class FirstScreen extends MainScreen {<\/p>\n<p>FirstScreen(){<\/p>\n<p>LabelField appTitle = new LabelField(&quot;HelloWorld Sample&quot;, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);<\/p>\n<p>this.setTitle(appTitle);<\/p>\n<p>RichTextField&amp;amp;nbsp; greeting = new RichTextField(&quot;its running\u2026 great \u201c);<\/p>\n<p>this.add(greeting);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>[\/code]<\/p>\n<p>Our screen is ready. Now time is to link it with our main program .i.e. \u00a0FirstBlackBerryClass. We have learned that to show a screen in blackberry application, we have to push it, so to show our FirstScreen, we will push it to in our FirstBlackBerryClass\u00a0class.<\/p>\n<p>For this we will use pushScreen method of UiApplication class that takes a reference of a Screen object. We will call this method in constructor of our FirstBlackBerryClass\u00a0class so that as soon as our application run, it push our screen to display on user\u2019s device.<\/p>\n<p>Now go back to FirstBlackBerryClass\u00a0class\u2019s constructor and the following line there.<\/p>\n<p>[code language=&#8221;java&#8221;]<\/p>\n<p>pushScreen(new FirstScreen());<\/p>\n<p>[\/code]<\/p>\n<p>its done \u2026 we have done .. now our final code should look like that<\/p>\n<p>\/\/======================<\/p>\n<p>[code language=&#8221;java&#8221;]<\/p>\n<p>package com.iainteractive.blackberry;<\/p>\n<p>import net.rim.device.api.ui.UiApplication;<\/p>\n<p>public class FirstBlackBerryClass&amp;amp;nbsp;extends UiApplication {<\/p>\n<p>public static void main(String[] args) {<\/p>\n<p>FirstBlackBerryClass&amp;amp;nbsp;firstApplication&amp;amp;nbsp; = new FirstBlackBerryClass();<\/p>\n<p>firstApplication.enterEventDispatcher();<\/p>\n<p>}<\/p>\n<p>public FirstBlackBerryClass(){<\/p>\n<p>pushScreen(new FirstScreen());<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/\/======================<\/p>\n<p>package com.iainteractive.blackberry;<\/p>\n<p>import net.rim.device.api.ui.container.MainScreen;<\/p>\n<p>import net.rim.device.api.ui.component.LabelField;<\/p>\n<p>import net.rim.device.api.ui.component.RichTextField;<\/p>\n<p>final class FirstScreen extends MainScreen {<\/p>\n<p>FirstScreen(){<\/p>\n<p>LabelField appTitle = new LabelField(&quot;HelloWorld Sample&quot;, LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);<\/p>\n<p>this.setTitle(appTitle);<\/p>\n<p>RichTextField&amp;amp;nbsp; greeting = new RichTextField(&quot;its running\u2026 great\u201c);<\/p>\n<p>this.add(greeting);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>\/\/======================<\/p>\n<p>[\/code]<\/p>\n<p>&nbsp;<\/p>\n<h2><span style=\"color: #000000;\">Test Your Application in the Simulator<\/span><\/h2>\n<p>for testing application in device simulator, do the following steps, \u00a0click on Run or the green shortcut icon on the toolbar. <img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-476\" title=\"run\" src=\"https:\/\/AasimNaseem.com\/wp-content\/uploads\/2009\/10\/run.jpg\" alt=\"run\" width=\"122\" height=\"75\" \/><\/p>\n<p>when your simulator starts, find and start your application from Downloads folder.<\/p>\n<p>When you run the application you should see\u00a0<span style=\"color: #993300;\"><strong>its running\u2026 great <\/strong>message.<\/span><\/p>\n<p><span style=\"color: #993300;\"><span style=\"color: #000000;\">To exit the simulator, just close its window.<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello All; I wish you receive this post in the best of everything. This is the 3rd part of the BlackBerry Application Development Tutorial series.\u00a0 First of all, accept my apology for posting this post so late. I was busy with some other projects, and hence couldn&#8217;t find enough time&#8230;<\/p>\n","protected":false},"author":1,"featured_media":5213,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[58,207,209,210,213,214,291,364,388,389,581,711,797,798,874,983,1034,1086],"class_list":["post-467","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blackberry","tag-3rd-part-of-blackberry-application-development-tutorial","tag-blackberry-application-development","tag-blackberry-application-development-tutorial-part-2","tag-blackberry-application-development-tutorial-part-3","tag-blackberry-jde-component-packs","tag-blackberry-jde-plug-in-for-eclipse","tag-configuring-eclipse-with-blackberry","tag-eclipse-sdk","tag-first-application-for-blackberry","tag-firstblackberryclass","tag-java","tag-mainscreen","tag-net-rim-device-api-ui-container-mainscreen","tag-net-rim-device-api-ui-uiapplication","tag-push-pop-of-screens","tag-test-your-application-in-the-simulator","tag-uiapplication","tag-welcomeblackberry-project"],"_links":{"self":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/467","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/comments?post=467"}],"version-history":[{"count":3,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/467\/revisions"}],"predecessor-version":[{"id":5215,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/posts\/467\/revisions\/5215"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media\/5213"}],"wp:attachment":[{"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/media?parent=467"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/categories?post=467"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/aasimnaseem.com\/blog\/wp-json\/wp\/v2\/tags?post=467"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}