smartrcp开源平台应用Java与Flex构建桌面程序 一(smartrcp版hello world)
安装配置
首先到:http://smartrcp.googlecode.com/files/smartrcp_1.0.a_20100429.rar
下载最新版的 smartrcp 开发包。
解压后双击 smartrcp.exe 就可启动 smartrcp 平台,如下图:
如果启动失败原因有二:
1 :检查 flash player 播放器是否是最新版(要求 ActiveX 版的)。
2 :检查 jre 是否配置正确(jre要求1.5以上)。
编写程序
1 :首先打开 Flex Builder 创建一名为 smartrcpDemo 的 Web application 类型程序,拷贝
Smartrcp 解压目录中 公用库 子目录下的 cn.smartinvoke_2.0_20100428.swc 与
org.smartrcp_1.0.a_20100428.swc 两个库文件到 smartrcpDemo 项目下的 libs 目录下。
2 :在 smartrcpDemo 项目下的 src 目录中 新建名为 Test.mxml 的 mxml application 类型 文件。
修改该文件内容如下:
<?xml version="1.0" encoding="utf-8"?> <rcp:RCPApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:rcp="http://www.smartrcp.org" backgroundColor="white" layout="vertical" verticalAlign="middle" paddingLeft="0" paddingRight="0" paddingBottom="0" paddingTop="0" creationComplete="debugSetting()" > <mx:Style> global{ font-size:12px; } </mx:Style> <mx:Script> <![CDATA[ import mx.utils.ColorUtil; import cn.smartinvoke.smartrcp.gui.module.CRGB; import cn.smartinvoke.smartrcp.gui.module.CommonDialogs; function debugSetting():void{ } function onOpenClick():void{ /** *打开颜色对话框,并将返回的颜色值设置为当前application的背景颜色。 * */ CommonDialogs.Instance.openColorDialog(function (ret:CRGB):void{ var colorStr:String="0x"+ret.red.toString(16)+ret.green.toString(16)+ret.blue.toString(16); this.setStyle("backgroundColor",colorStr); },this); } ]]> </mx:Script> <mx:Button label="打开对话框" click="onOpenClick()"/> </rcp:RCPApplication>
最后保存编译。该程序的功能为点击 打开对话框 按钮 就会显示windows的颜色对话框,并用该颜色对话框返回的颜色值设置该程序的背景色。标准Flex程序中是无法打开windows的颜色对话框的。
3: 在Flex builder 中单击Windows -> Preferences
打开Preferences窗口,选择General 下的 Web Browser 选项卡,单击
New按钮以添加名为smartrcp的新浏览器,设置该浏览器的路径为smartrcp解压目录下的DebugConnector.exe文件,最后选
中该smartrcp 浏览器为Flex运行程序的浏览器。
4:运行smartrcp.exe程序启动smartrcp开发平台,然后在Flex Builder中运行第二步写好的Test.mxml程序,启动后的效果如下:
如果出现swf无法加载的情况,请:
下载 http://smartinvoke.googlecode.com/files/DebugConnector.rar 替换smartrcp解压目录下的DebugConnector.exe