Code Sample: A Helloworld Application - Blackberry JAVA DEVELOPMENT ENVIRONMENT Getting Started Manual

Device application development
Hide thumbs Also See for JAVA DEVELOPMENT ENVIRONMENT:
Table of Contents

Advertisement

6. Close the BlackBerry device application.

Code sample: A HelloWorld application

The following sample code pulls together the tasks in this section into an BlackBerry® device application that
displays the text 'Hello World!' on the BlackBerry smartphone screen and displays a dialog box with the text
'Goodbye!' when the BlackBerry device application closes.
/**
Example:
* HelloWorld.java
* Copyright (C) 2001-2008 Research In Motion Limited. All rights reserved.
*/
package com.rim.samples.helloworld;
import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;
/*
* BlackBerry device applications that provide a UI
* must extend the UiApplication class.
*/
public class HelloWorld extends UiApplication
{
public static void main(String[] args)
{
//Create a new instance of the BlackBerry device pplication
//and start the BlackBerry device application on the event thread.
HelloWorld theApp = new HelloWorld();
theApp.enterEventDispatcher();
}
public HelloWorld()
{
//Display a new screen.
pushScreen(new HelloWorldScreen());
}
}
//Create a new screen that extends MainScreen and provides
//behaviour similar to that of other BlackBerry device applications.
final class HelloWorldScreen extends MainScreen
{
public HelloWorldScreen()
{
//Invoke the MainScreen constructor.
super();
//Add a title to the screen.
LabelField title = new LabelField("HelloWorld Sample", LabelField.ELLIPSIS
setTitle(title);
| LabelField.USE_ALL_WIDTH);
2: Create a basic BlackBerry device application
15

Advertisement

Table of Contents
loading

Table of Contents