Simple User Interface Application Using a Label Text Field and Button

The goal of this application is to have the user enter his or her name into a text box, press a button, and have the BlackBerry greet them by name (Figure 4-7). You can compare this application and the process to the iPhone version from Chapter 2.

Figure 4-7. Hello BlackBerry Application Running in the Simulator

First, set up a new BlackBerry Project. We explained how to setup and configure a new BlackBerry project in the previous example. Next, we will create a new project called User Interface and a new class that extends UiApplication called UserInterface.

Replace the contents of the generated UserInterface with the source code of the completed User Interface application that follows.

import net.rim.device.api.ui.*;

import net.rim.device.api.ui.component.*;

import net.rim.device.api.ui.container.*;

public class UserInterface extends UiApplication {

public static void main(String []args) {

UserInterface theApp = new UserInterface(); theApp.enterEventDispatcher();

public UserInterface () {

pushScreen (new UserInterfaceScreen());

class UserInterfaceScreen extends MainScreen implements FieldChangeListener {

LabelField greetingLabel; BasicEditField userNameField; ButtonField helloBtn;

public UserInterfaceScreen() {

LabelField title = new LabelField("XPlatform Dev"); setTitle(title);

greetingLabel = new LabelField(""); add(greetingLabel);

userNameField = new BasicEditField("Name: ", ""); add(userNameField);

helloBtn = new ButtonField("Hello BlackBerry!",^ ButtonField.CONSUME_CLICK);



public void fieldChanged(Field field, int context) {

greetingLabel.setText("Hello " + userNameField.getText());

public boolean onClose() {

System.exit(0); return true;

Was this article helpful?

0 0
iPhone and iPad App Cash

iPhone and iPad App Cash

Discover how a single application could generate $1000's of dollars, instantly. The simple, low cost system for outsourcing app development to freelancers. How to quickly evaluate applications so you can create a high profit one of your very own. The fastest way to leverage the popularity of iPhone and iPad apps to skyrocket your income. Top methods for promoting your application for maximum exposure.

Get My Free Ebook

Post a comment