Writing BlackBerry Java applications

Source: Internet
Author: User

Author:ConfachPublished on March pm
Copyright information: Can be reproduced at will. During reprinting, be sure to mark it as a hyperlinkArticleOriginal SourceAnd author information.
Http://www.cnblogs.com/confach/articles/358028.html

[Url =] No2[/Url]Chapter
WriteBlackberry JavaApplicationProgram

[p = 19, null, left] application management

[p = 19, null, left] compile a routine

[p = 19, null, left] reuse Code

[p = 19, null, left] use BlackBerry ide

[p = 19, null, left] use command line

[p = 19, null, left] use a Bluetooth Development Environment

[p = 19, null, left] use eclipse Development Environment

[p = 19, null, left] programming guide

[Url =] Application Management [/url]
[P = 19, null, left] WhenBlackberryWhen the device starts, the VM loads the application manager, which is managed inBlackberryAll programs running on the device. For other Java programs, the functions of the Application Manager are similar to those of the central dispatcher for operating system events.

 

[P = 19, null, left] applications that provide user interfaces extend the net. Rim. device. API. UI. uiapplication class. This class provides methods for applications to register event listeners, manage threads, and UI components.

 

[P = 19, null, left] applications that do not provide user interfaces extend the net. Rim. device. API. system. Application class.

 

[P = 19, null, left]BlackberryThe application starts with the main () function. When a program starts, its main () thread calls entereventdispatcher () to start processing events. This thread runs all the code for drawing and event processing, and logs events in the application queue.

 

[P = 19, null, left] When the application manager receives an event, it copies the event to the appropriate queue, this queue allows the application manager to direct messages to specific programs. For example, a foreground application only receives user-input messages.

 

[Url =] compile a routine [/url]
[Url =] extension [/url]UiapplicationBase Class
[P = 19, null, left] Each application that provides user interfaces extends the uiapplication base class. The uiapplication class defines a method for the application to create an event thread, and display and maintain screen objects.

 

[Url =] define [/url]Main ()
[P = 19, null, left] InMain ()To create a new object for the application. Call entereventdispatcher () to open the application into the event thread and start to process the message.

 

Public
Static
Void Main (string [] ARGs ){
Helloworld theapp = New Helloworld ();
Theapp. entereventdispatcher (); }

[Url =] define a constructor [/url]
[P = 19, null, left] defines the default constructor for your application. The default constructor calls uiapplication. pushscreen () to display the screen when the application starts. In this example, the screen creates a new helloworldscreen instance, which is defined in the following code:

 

Public helloworld () {
pushscreen ( New helloworldscreen ()); }

[Url =] define [/url]MainScreen
[P = 19, null, left] extends the mainscreen class to define the main screen of the application UI. The mainscreen class is a subclass of screen. It implements trackwheellistener and keyboardlistener interfaces that receive and respond to user interaction. If you expand one of the screen class or its sub-classes, you do not have to implement the trackwheellistener and keyboardlistener interfaces.

 

[P = 19, null, left] Your class should override at least two mainscreen methods: the default constructor and onclose ().

 

[P = 19, null, left] In this example, the constructor calls the constructor of mainscreen. By default, mainscreen provides the following features:

 

    • ByCloseThe default menu of the menu item.
    • When you clickCloseOr pressEscapeIs disabled by default. To provide custom behaviors, for example, displaying a dialog box prompt, when a user clicksCloseMenu item or pressEscapeClick to override onclose ().
    • An instance of richtextfield, a read-only rich text field that can receive focus
      For more information about adding the UI component to the screen, see"Provides screen navigation"
    • OneSelectContext menu of the menu item?
      For more information, see "create custom context menu" On page 60.

[Url =] Code instance [/url]
[P = 19, null, left] the following example creates a screen that contains a rich text field. When the Rich Text Field receives the focus, the menu guard has a close menu item and a select context menu item.

 

[P = 19, null, left]

 

[P = 19, null, left] example: helloworld. Java

 

[P = 19, null, left]/**

 

[P = 19, null, left]
*
Helloworld. Java

 

[P = 19, null, left]
*
Copyright
(C)
2001 - 2005
Research
In
Motion
Limited.
All
Rights
Reserved.

 

[P = 19, null, left]
*/

 

[P = 19, null, left]

 

[P = 19, null, left]PackageCom.rim.samples.doc S. helloworld;

 

[P = 19, null, left]ImportNet. Rim. device. API. UI .*;

 

[P = 19, null, left]ImportNet. Rim. device. API. UI. component .*;

 

[P = 19, null, left]ImportNet. Rim. device. API. UI. Container .*;

 

[P = 19, null, left]ImportNet. Rim. device. API. system .*;

 

[P = 19, null, left]ImportCom.rim.samples.doc S. Resource .*;

 

[P = 19, null, left]

 

[P = 19, null, left]Public
ClassHelloworldExtendsUiapplication {

 

[P = 19, null, left]
Public
Static
VoidMain (string [] ARGs ){

 

[P = 19, null, left]
Helloworld theapp =NewHelloworld ();

 

[P = 19, null, left]
Theapp. entereventdispatcher ();

 

[P = 19, null, left]
}

 

[P = 19, null, left]

 

[P = 19, null, left]
PublicHelloworld (){

 

[P = 19, null, left]
Pushscreen (NewHelloworldscreen ());

 

[P = 19, null, left]
}

 

[P = 19, null, left]
}

 

[P = 19, null, left]

 

[P = 19, null, left]

 

[P = 19, null, left]Final
ClassHelloworldscreenExtendsMainscreen {

 

[P = 19, null, left]
PublicHelloworldscreen (){

 

[P = 19, null, left]
Super();

 

[P = 19, null, left]

Labelfield Title =NewLabelfield ("helloworld sample", labelfield. ellipsis

 

[P = 19, null, left]
| Labelfield. use_all_width );

 

[P = 19, null, left]
Settitle (title );

 

[P = 19, null, left]
Add (NewRichtextfield ("Hello world !"));

 

[P = 19, null, left]
}

 

[P = 19, null, left]

 

[P = 19, null, left]
Public
BooleanOnclose (){

 

[P = 19, null, left]
Dialog. Alert ("goodbye !");

 

[P = 19, null, left]
System. Exit (0 );

 

[P = 19, null, left]
Return
True;

 

[P = 19, null, left]
}

 

[P = 19, null, left]
}

 

[P = 19, null, left]

 

[Url =] reuse Common Code [/url]
[P = 19, null, left] Abstract base classes allow you to implement and reuse general functions across multiple classes. Each application can expand a single base class. InBlackberryIDE to add the base class to a library project. Create an independent project for each application and define the dependencies of the Library Project.

 

[Url =] Code instance [/url]
[P = 19, null, left] The routine in this Guide extends the baseapp class, which implements the following functions:

 

    • Extended uiapplication class
    • Implement the keylistener and trackwheellistener Interfaces
    • Define variables, such as general menu items
    • Define a method to create an application menu.
    • Define a method for the menu
    • Define an abstract method to exit the program

This article is transferred fromWww.35java.com

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.