In this lesson, you create a class with a main method that opens a HomeScreen, which contains a title and a status message.
In the workspace view, right-click the project and choose Create New File In Project.
In the Source File Name box, type myapp\Application.java to create a file named Application.java that is part of the myapp package.
Click OK to create the file. The Application class appears in the JDE window.
Define the Application class. No imports are needed for this class. Add a constructor and a main method so that your Application class is defined as follows:
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 the HomeScreen class to your project.
In the workspace view, right-click the project and choose Create New File In Project.
In the Source File Name box, type myapp\HomeScreen.java.
Click OK to create the file.
The HomeScreen class appears in the JDE window.
Define the HomeScreen class so that it displays a title and a Status message.
package myapp; 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.
Right-click the project and choose Build. Ensure that it compiles without errors.
Press F5 to run the application in the device simulator.
The BlackBerry simulator launches in a separate window.
On the simulator, navigate to the Applications window and select the HelloBlackBerry application.
Start the application.
A window appears showing the title bar Hello BlackBerry and the status line Status: started.
From the JDE Debug menu choose Stop Debugging.
The simulator terminates.
Discuss this page in DocCommentXchange.
|
Copyright © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |