参考网上的资料实现重力传感器在图形上的显示,使用Blazeds 的server push机制实现功能。
1.java代码sensor的三个轴,x y z
public class Gsensor {
private String month;
private int xValue;
private int yValue;
private int zValue;
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public int getXValue() {
return xValue;
}
public void setXValue(int value) {
xValue = value;
}
public int getYValue() {
return yValue;
}
public void setYValue(int value) {
yValue = value;
}
public int getZValue() {
return zValue;
}
public void setZValue(int value) {
zValue = value;
}
2.开启线程每一秒中向客户端发送数据
public class GsensorChartPush implements Runnable {
@Override
public void run() {
while(true){
List<Gsensor> gsensor = getGsensor();
MessageFactory.sendMsg("gsensorpush",gsensor);
try{
Thread.sleep(1000);
}catch(InterruptedException se){
se.printStackTrace();
}
}
}
private List<Gsensor> getGsensor() {
List<Gsensor> gList = new ArrayList<Gsensor>();
for(int i=0;i<5;i++){
Random random = new Random();
String month = i == 1 ? "January" : i == 2 ? "February" : i==3 ? "February":i==4 ? "April":i==5?"May":"June";
Gsensor gsensor = new Gsensor();
gsensor.setMonth(month);
gsensor.setXValue(random.nextInt(10));
gsensor.setYValue(random.nextInt(20));
gsensor.setZValue(random.nextInt(30));
gList.add(gsensor);
}
return gList;
}
3.MessageFactory工厂实现消息的发送
public class MessageFactory {
private static MessageBroker msgBroker = MessageBroker.getMessageBroker(null);
private static String clientId = UUIDUtils.createUUID();
public static void sendMsg(String destination,Object body){
AsyncMessage msg = new AsyncMessage();
msg.setDestination(destination);
msg.setClientId(clientId);
msg.setMessageId(UUIDUtils.createUUID());
msg.setTimestamp(System.currentTimeMillis());
msg.setBody(body);
msgBroker.routeMessageToService(msg, null);
}
}
4.配置blazeds messing-config.xml
<destination id="gsensorpush">
<properties>
<server>
<allow-subtopics>true</allow-subtopics>
<subtopic-separator>.</subtopic-separator>
</server>
</properties>
<channels>
<channel ref="my-polling-amf"/>
</channels>
</destination>
5.flex前端页面代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" creationComplete="init()">
<mx:Script>
<![CDATA[
import mx.messaging.events.MessageFaultEvent;
import mx.rpc.events.ResultEvent;
import mx.messaging.events.MessageEvent;
import mx.collections.ArrayCollection;
import mx.controls.Alert;
private function init():void{
consumer.subscribe();
}
private function messageHandler(event:MessageEvent):void{
lineChart.dataProvider = event.message.body;
}
private function messageFault(event:MessageFaultEvent):void{
Alert.show("接收错误");
}
]]>
</mx:Script>
<mx:Consumer id="consumer" destination="gsensorpush" message="messageHandler(event)" fault="messageFault(event)"/>
<mx:SolidColor id="sc1" color="blue" alpha=".3"/>
<mx:SolidColor id="sc2" color="red" alpha=".3"/>
<mx:SolidColor id="sc3" color="green" alpha=".3"/>
<mx:Stroke id = "s1" color="blue" weight="2"/>
<mx:Stroke id = "s2" color="red" weight="2"/>
<mx:Stroke id = "s3" color="green" weight="2"/>
<mx:Panel title="DateTimeAxis Example" height="100%" width="100%">
<mx:LineChart id="lineChart" height="100%" width="45%"
paddingLeft="5" paddingRight="5"
showDataTips="true">
<mx:horizontalAxis>
<mx:DateTimeAxis dataUnits="seconds"/>
</mx:horizontalAxis>
<mx:series>
<mx:LineSeries yField="XValue" form="curve" displayName="X" lineStroke="{s1}"/>
<mx:LineSeries yField="YValue" form="curve" displayName="Y" lineStroke="{s2}"/>
<mx:LineSeries yField="ZValue" form="curve" displayName="Z" lineStroke="{s3}"/>
</mx:series>
</mx:LineChart>
</mx:Panel>
</mx:Application>
- 大小: 21.4 KB
分享到:
相关推荐
FLEX 动态树 动态图表 FLEX 动态树 动态图表
Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表制作Flex图表...
flex 3.5 中动态生成 图表代码实现
H3C FlexServer R690服务器技术白皮书.docx
使用flex写的四种图表,用于web前台显示,加入了保存图表图片的功能。
NULL 博文链接:https://zh-dream-success.iteye.com/blog/1685423
chart.rar--java+flex图表 Flex3高级图表开发指南.pdf--英文的 Flex+白皮书.pdf flex-demo.rar Flex入门培训资料及PPT.rar flex中文帮助.pdf InfoQ Flex与JSON及XML的互操作.mht 结合java做的flex图表例子 - 点点...
包中带有4个flex 项目工程,其中有图表库文件(flare),图表示例项目demos),是非常完整的flex 动画图表的算法实现与图形实现,是学习的非常好的源码
flexBulider页面加载动态图片的显示
flex柱状图表很漂亮的源码
NULL 博文链接:https://zh-dream-success.iteye.com/blog/1685429
H3C_FlexServer服务器产品故障处理手册1 服务器相关故障处理方法1.2 刀片服务器开机故障排查流程
Flex图表插件
NULL 博文链接:https://dojava.iteye.com/blog/1711575
Flex与Java实现通信,Flex与Java实现通信,Flex与Java实现通信
H3C FlexServer R690 服务器操作系统安装 肖永新-2014年10月整理 项目经验娄底教育局云平台 注!在引导安装操作系统之前,首先要配置raid,否则找不到硬盘(raid配置,详见R 690服务器raid配置部分),其次配置...
Flex3高级图表开发指南
圆形图表展示源码
一个基于flex的拖拽框架,可以通过框架类直接塞入需要拖拽的控件达到效果,还有实现了服务