Hello World en BlackBerry Storm

·

En este post describiremos cómo crear un simple aplicación Hello World! para la BlackBerry 9530 Storm (con pantalla táctil).

Para el desarrollo de este ejemplo se ha usado el entorno de desarrollo BlackBerry JDE en su versión 4.7.0

Necesitaremos crear:
- Una clase HelloWorldDemo, que será la base de nuestra aplicación, y que extenderá de UiApplication
- Una clase HelloWorldScreen, que será la pantalla que se mostrará en la BlackBerry, y que extenderá de MainScreen. La pantalla contendrá un título, un texto y un mensaje tipo Alert al cerrar la aplicación.


De esta manera, el archivo HelloWorldDemo.java tendrá el siguiente código:


//paquete al que pertenece
package com.rim.samples.device.helloworlddemo;

//importaciones
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.component.RichTextField;

//clase de nuestra aplicación
class HelloWorldDemo extends UiApplication
{
/**
* Entry point for application.
*/
public static void main(String[] args)
{
// Create a new instance of the application.
HelloWorldDemo theApp = new HelloWorldDemo();

// To make the application enter the event thread and start processing messages,
// we invoke the enterEventDispatcher() method.
theApp.enterEventDispatcher();
}

/**
* The default constructor. Creates all of the RIM UI components and pushes the
* application's root screen onto the UI stack.
*/
private HelloWorldDemo()
{
// Push the main screen instance onto the UI stack for rendering.
pushScreen(new HelloWorldScreen());
}
}


//clase de la pantalla
//al extender de MainScreen, nos ahorramos controlar los eventos habituales en estas aplicaciones,
//aunque como es natural se pueden sobreescribir (en este ejemplo sobreescribiremos el método close)
final class HelloWorldScreen extends MainScreen
{

//constructor
HelloWorldScreen()
{
// Add a field to the title region of the screen. We use a simple LabelField
// here. The ELLIPSIS option truncates the label text with "..." if the text
// is too long for the space available.
LabelField title = new LabelField("Hello World Demo (Título)" , LabelField.ELLIPSIS LabelField.USE_ALL_WIDTH);
setTitle(title);

// Add a read only text field (RichTextField) to the screen. The RichTextField
// is focusable by default. In this case we provide a style to make the field
// non-focusable.
add(new RichTextField("Hello World! (Texto)" ,Field.NON_FOCUSABLE));
}

/**
* Display a dialog box to the user with "¡Aaaadiós!" when the application
* is closed.
*
* @see net.rim.device.api.ui.Screen#close()
*/
public void close()
{
// Display a farewell message before closing application.
Dialog.alert("¡Aaaadiós!");
System.exit(0);

super.close();
}

} //fin clase



Para probar nuestro ejemplo:
- Dentro del JDE, haremos click en Debug -> Go, o pulsaremos F5
- Se abrirá el simulador
- En el teléfono, pulsaremos la tecla de menú (logotipo de BlackBerry)
- Pulsaremos Downloads
- Buscaremos nuestra aplicación Hello World

Imagen: