O'Reilly logo

BlackBerry Hacks by Dave Mabe

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Hack #95. Create a Simple Stock Quote Application

Build a simple stock quote application that will prompt a user for a stock symbol, then perform an HTTP request to the Yahoo! stock quote server, and finally display the stock price.

To create BlackBerry applications, you must download and install the Black-Berry Java Development Environment (JDE) from the http://www.blackberry.com web site. The JDE contains the development environment, compiler, MDS Simulator, and the BlackBerry Device simulator [Hack #93] . Once the JDE is installed, you are ready to start writing your application.

Launch the JDE, and create a new workspace and a project and call it whatever you want. Then add a new .java file to your project. The simplest version of a BlackBerry UI application must simply contain a public static void main(String[] args) method. Here is an example of the simplest BlackBerry application:

	import net.rim.device.api.ui.*;
	public class StockQuotes extends UIApplication {
		public static void main(String[] args) {
		}
	}

This application does not do anything—it does not even display a user interface. The next step is to create a user interface.

For this stock quote example, we will simply show a text input field in which the user can enter the stock symbol:

 import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; public class StockQuotes extends UIApplication { public static void main(String[] args) { StockQuotes theApp = new StockQuotes(); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required