黑莓开发学习入门系列,自己动手实现一个日历软件(二)
搭建好开发环境后我们就要运行helloword了,
新建一个Project打开工程视图,选择BlackBerry Project
输入工程名,选择对应的BlackBerry JRE版本,本人刷的是4.2的OS,老型号的机器但是相当经典。
目录结构应该是这样的
新建两个类,一个用于主程序,一个用于屏幕显示,下来会解释缘由
HelloWorldMain主类,让它继承net.rim.device.api.ui.UiApplication,作为一个主应用程序的事件线程,显示和维护屏幕对象。HelloWorldScreen类,继承net.rim.device.api.ui.container.MainScreen,作为当前显示的应用程序屏幕,从字面意思也不难理解。 在HelloWorldScreen类的构造函数中直接显示一个Label 在主类中实例化屏幕类,并将此屏幕类的实例压入当前屏幕队列,调用enterEventDispatcher()启动主线程执行。完整的代理如下:
package
org.bulktree;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class HelloWorldScreen extends MainScreen {
public HelloWorldScreen() {
add( new LabelField( " Hello World! " ));
}
}
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.MainScreen;
public class HelloWorldScreen extends MainScreen {
public HelloWorldScreen() {
add( new LabelField( " Hello World! " ));
}
}
package
org.bulktree;
import net.rim.device.api.ui.UiApplication;
public class HelloWorldMain extends UiApplication {
public HelloWorldMain() {
HelloWorldScreen hws = new HelloWorldScreen();
pushScreen(hws);
}
public static void main(String[] args) {
HelloWorldMain hw = new HelloWorldMain();
hw.enterEventDispatcher();
}
}
import net.rim.device.api.ui.UiApplication;
public class HelloWorldMain extends UiApplication {
public HelloWorldMain() {
HelloWorldScreen hws = new HelloWorldScreen();
pushScreen(hws);
}
public static void main(String[] args) {
HelloWorldMain hw = new HelloWorldMain();
hw.enterEventDispatcher();
}
}
如何让你模拟器显示中文呢? components\simulator\8700.xml(或者8700-black.xml),在<Application>net.rim.blackberry.lang.en_GB</Application>后加入下面两行:
<
Application
>
net.rim.blackberry.lang.zh_CN_Pinyin
</
Application
>
<
Application
>
net.rim.blackberry.lang.zh_CN.renderingSupport
</
Application
>
完整的配置如下:
<
SimulatorConfiguration
version
="1.0"
hardwareid
="0x84000B03"
flashSize
="32768"
platformVersion
="1.8.0.0"
vendorID
="0"
>
< ALXSources > . </ ALXSources >
< Application > net.rim.java.tasks </ Application >
< Application > net.rim.java.memopad </ Application >
< Application > net.rim.medialoader.video </ Application >
< Application > net.rim.java.docViewer </ Application >
< Application > net.rim.java.passwordkeeper </ Application >
< Application > net.rim.blackberry.lang.en_GB </ Application >
< Application > net.rim.blackberry.lang.zh_CN_Pinyin </ Application >
< Application > net.rim.blackberry.lang.zh_CN.renderingSupport </ Application >
< Application > net.rim.blackberry.spellcheck </ Application >
< Application > net.rim.platform.ecmascript </ Application >
< Application > com.dataviz.dxtg </ Application >
< Application > net.rim.java.phone </ Application >
< Application > net.rim.java.browser </ Application >
< Application > net.rim.java.browser.javascript </ Application >
< ApplicationExclude > net.rim.BBXpEnabler </ ApplicationExclude >
< ApplicationExclude > net.rim.java.batterylog </ ApplicationExclude >
< ApplicationExclude > net.rim.java.quincy </ ApplicationExclude >
< ApplicationExclude > net.rim.java.linktrack </ ApplicationExclude >
< Application > net.rim.java.help </ Application >
< Application > net.rim.java.maps </ Application >
< Application > net.rim.java.blackberrymessenger </ Application >
< Application > net.rim.sdk.simulator </ Application >
</ SimulatorConfiguration >
< ALXSources > . </ ALXSources >
< Application > net.rim.java.tasks </ Application >
< Application > net.rim.java.memopad </ Application >
< Application > net.rim.medialoader.video </ Application >
< Application > net.rim.java.docViewer </ Application >
< Application > net.rim.java.passwordkeeper </ Application >
< Application > net.rim.blackberry.lang.en_GB </ Application >
< Application > net.rim.blackberry.lang.zh_CN_Pinyin </ Application >
< Application > net.rim.blackberry.lang.zh_CN.renderingSupport </ Application >
< Application > net.rim.blackberry.spellcheck </ Application >
< Application > net.rim.platform.ecmascript </ Application >
< Application > com.dataviz.dxtg </ Application >
< Application > net.rim.java.phone </ Application >
< Application > net.rim.java.browser </ Application >
< Application > net.rim.java.browser.javascript </ Application >
< ApplicationExclude > net.rim.BBXpEnabler </ ApplicationExclude >
< ApplicationExclude > net.rim.java.batterylog </ ApplicationExclude >
< ApplicationExclude > net.rim.java.quincy </ ApplicationExclude >
< ApplicationExclude > net.rim.java.linktrack </ ApplicationExclude >
< Application > net.rim.java.help </ Application >
< Application > net.rim.java.maps </ Application >
< Application > net.rim.java.blackberrymessenger </ Application >
< Application > net.rim.sdk.simulator </ Application >
</ SimulatorConfiguration >
都OK了,后我们发现模拟器上应用程序图标是一个命令行窗口,如何实现一个我们自己的图标呢。在工程中产生一个res文件夹,我们可以把资源文件都放在此目录下。copy一个图标过来,可以去自带的components\samples 下找一个,也可以自己做一个,但是尺寸要把握好哦
注意到工程下的此BlackBerry_App_Descriptor.xml文件了吗?这次派上用场了,
此时运行模拟器看看是不是变化了:
我取的是默认例子下的图标哦。