In this lesson, you create a class with a main method that opens a HomeScreen class, which contains a title and a status message.
Add an Application class to your project.
In the Package Explorer window, expand HelloBlackBerry and click src.
Click File » New » Class.
The New Java Class window appears.
In the Name field, type Application.
Under the Which Method Stubs Would You Like To Create option, select Public Static Void Main([String() Args]).
Click Finish.
The Application.java file appears under your project in the Package Explorer window.
Modify the Application class.
Double-click Application.java in the Package Explorer window, and then add a constructor and a main method.
Your Application.java code should look like the following code:
class Application extends net.rim.device.api.ui.UiApplication { public static void main( String[] args ) { Application instance = new Application(); instance.enterEventDispatcher(); } Application() { pushScreen( new HomeScreen() ); } } |
Add a HomeScreen class to your project.
In the Package Explorer window, expand HelloBlackBerry and click src.
Click File » New » Class.
The New Java Class window appears.
In the Name field, type HomeScreen.
Click Finish.
The HomeScreen.java file appears under your project in the Package Explorer window.
Modify the HomeScreen class so that it displays a title and status messages.
Double-click HomeScreen.java in the Package Explorer window, and then update the code so that it displays a title and a status message.
Your HomeScreen.java code should look like the following code:
import net.rim.device.api.ui.*; import net.rim.device.api.ui.component.*; import net.rim.device.api.ui.container.*; import java.util.*; class HomeScreen extends MainScreen { HomeScreen() { // Set the window title LabelField applicationTitle = new LabelField("Hello BlackBerry"); setTitle(applicationTitle); // Add a label to show application status _statusLabel = new LabelField( "Status: Started" ); add( _statusLabel ); } private LabelField _statusLabel; } |
The _statusLabel is defined as a class variable so that it can be accessed from other parts of the application later.
Run the simulator.
In the Package Explorer window, click Application.java, and then click Run » Run As » BlackBerry Simulator.
If multiple projects are open in your workspace, click Run » Run Configurations, select HelloBlackBerry, and then click Run.
The HelloBlackBerry project compiles and then the simulator window appears.
Ensure that the project compiles without errors by selecting the Problems tab in Eclipse.
From the simulator menu, click Simulate » Set IT Policy.
The Set IT Policy window appears.
In the Policy field, click Allow Third Party Apps To Use Persistent Store » >>.
Click Set and then click Close.
Launch your application.
In the simulator window, navigate to Downloads and then run the HelloBlackBerry application.
A screen appears that displays the Hello BlackBerry title bar and the Status: Started text.
Stop the simulation.
In the simulator window, click File » Exit.
Discuss this page in DocCommentXchange.
|
Copyright © 2012, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.1 |