java ArrayList 转成Flex ArrayCollection
2010-06-13 00:57
603 查看
1. server
2.client
3. 配置文件:
package com.east.flex.serverpush; import java.util.ArrayList; import java.util.List; import java.util.Random; import com.east.flex.serverpush.entity.Product; /** * * @author East(张栋芳) * * 2010-6-13 */ public class CreateProduct extends Thread { private List<Product> productList = new ArrayList<Product>(); public CreateProduct() { // this.start(); } @Override public void run() { // while (true) { // // Product p = new Product(); // Random random = new Random(); // p.setMonth("Jan"); // p.setProfit(random.nextInt(1000)); // p.setExpenses(random.nextInt(500)); // p.setAmount(random.nextInt(300)); // // productList.add(p); // if (productList.size() == 15) { // try { // break; // } catch (Exception se) { // System.out.println(se.getMessage()); // } // } // System.out.println("Size is :" + productList.size()); // } } public List<Product> getProductList() { for (int i = 0; i < 3; i++) { Product p = new Product(); Random random = new Random(); p.setMonth("Jan" + i); p.setProfit(random.nextInt(1000)); p.setExpenses(random.nextInt(500)); p.setAmount(random.nextInt(300)); productList.add(p); } return productList; } public Product getProduct() { Product p = new Product(); Random random = new Random(); p.setMonth("Jan"); p.setProfit(random.nextInt(1000)); p.setExpenses(random.nextInt(500)); p.setAmount(random.nextInt(300)); return p; } public void setProductList(List<Product> productList) { this.productList = productList; } }
2.client
<?xml version="1.0"?> <!-- Simple example to demonstrate the LineChart and AreaChart controls. --> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script>import com.east.flex.entity.Product</mx:Script> <mx:Script> <!--[CDATA[ import mx.utils.ArrayUtil; import mx.rpc.events.ResultEvent; import mx.collections.ArrayCollection; import mx.controls.Alert; [Bindable] private var p:Product; private var array:ArrayUtil; [Bindable] private var expensesAC:ArrayCollection = null; private function autoRefresh(event:MouseEvent):void { //serverPush.getProduct(); serverPush.getProductList(); } private function resultHandler(event:ResultEvent):void { //处理多个值 trace(event.result); //ArrayUtil.toArray(); linechart.dataProvider=event.result; /*处理一个值 p= event.result as Product; linechart.dataProvider= [ { Month: "Otc", Profit: p.profit, Expenses: p.expenses, Amount: p.amount }, { Month: "Jan", Profit: 500, Expenses: 800, Amount: 600 }, { Month: "Fre", Profit: 300, Expenses: p.expenses, Amount: p.amount }]; */ } ]]--> </mx:Script> <mx:RemoteObject id="serverPush" result="resultHandler(event)" destination="createProduct"/> <!-- Define custom colors for use as fills in the AreaChart control. --> <mx:SolidColor id="sc1" color="blue" alpha=".3"/> <mx:SolidColor id="sc2" color="red" alpha=".3"/> <mx:SolidColor id="sc3" color="green" alpha=".3"/> <!-- Define custom Strokes. --> <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="LineChart and AreaChart Controls Example" height="100%" width="100%" layout="absolute"> <mx:LineChart id="linechart" height="100%" width="1030" paddingLeft="5" paddingRight="5" showDataTips="true" x="0" y="0"> <mx:horizontalAxis> <mx:CategoryAxis categoryField="month"/> </mx:horizontalAxis> <mx:series> <mx:LineSeries yField="profit" form="curve" displayName="profit" lineStroke="{s1}"/> <mx:LineSeries yField="expenses" form="curve" displayName="expenses" lineStroke="{s2}"/> <mx:LineSeries yField="amount" form="curve" displayName="amount" lineStroke="{s3}"/> </mx:series> </mx:LineChart> <mx:Legend dataProvider="{linechart}" x="1038" y="0" width="107"/> <mx:Button label="AutoRefresh" x="1038" y="87" width="107" click="autoRefresh(event)"/> </mx:Panel> </mx:Application>
3. 配置文件:
<?xml version="1.0" encoding="UTF-8"?> <service id="remoting-service" class="flex.messaging.services.RemotingService"> <adapters> <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true" /> </adapters> <default-channels> <channel ref="my-amf" /> </default-channels> <destination id="createProduct"> <properties> <source>com.east.flex.serverpush.CreateProduct</source> </properties> </destination> </service>
相关文章推荐
- Flex, Array, ArrayList, ArrayCollection difference
- Flex, Array, ArrayList, ArrayCollection difference
- Java:集合,Array、Collection(List/Set/Queue)、Map的遍历,比如:ArrayList,LinkedList,HashSet,HashMap
- Java:concurrent包下面的Collection接口框架图( CopyOnWriteArraySet, CopyOnWriteArrayList,ConcurrentLinkedQueue,BlockingQueue)
- flex ArrayCollection的新增与删除的同步
- java中的ArrayList 、List、LinkedList、Collection关系详解
- JAVA/Array和List以及ArrayList
- Java中集合(一)Collection 、List<E> 、ArrayList<E>
- Java的数组(Array)、Vector、ArrayList、HashMap的异同
- Java ArrayList Collection.sort排序示例
- Java ArrayList转数组泛型方法错误ArrayStoreException处理办法
- java中Collection/Collections;List/Set/Map;ArrayList/Vector/LinkedList;HashSet/HashMap/TreeSet/TreeMap
- java中vector,array,list,arraylist的区别
- java.util.ArrayList.toArray(T[]) 方法实例
- Flex4 Array和Flex ArrayCollection的用法和区别
- JAVA ARRAY 和ArrayList
- JAVA学习笔记 -- Vector, ArrayList, Array
- Java中Array与ArrayList的主要区别
- Java多线程 -- JUC包源码分析2 -- Copy On Write/CopyOnWriteArrayList/CopyOnWriteArraySet
- java容器类分析:Collection,List,ArrayList,LinkedList深入解读