【原创】flex in action (六)flex与后台Java进行交互(2)

上一篇将架构已经做好了,
现在使用的就是交互程序了。
如图建立:

建立一个Java程序,切换到myeclipse视图下,在src下建立。
代码:
 1 package com.duduli.li;
 2 
 3 public class Input {
 4     public String display(String name,String sex,String email){
 5         System.out.println("your name is " + name);
 6         System.out.println("your sex is " + sex);
 7         System.out.println("your email is " + email);
 8         return "你的姓名是 " + name + "\t你的性别是 " + sex + "\t你的Email是 " + email;
 9     }
10 }
Input类下有个display方法,接受三个参数。然后返回一个字符串。
打开webroot/web-inf/flex,找到remoting-config.xml。
在service中加入。
1     <destination id="input">
2         <properties>
3     <source>com.duduli.li.Input</source>        <scope>application</scope>
4         </properties>
5     </destination>
然后就是界面的代码:
 1 <?xml version="1.0" encoding = "utf-8"?>      
 2 <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" 
 3      layout="absolute">      
 4 <mx:Script >      
 5   <![CDATA[ 
 6       import mx.rpc.events.FaultEvent;    
 7        import mx.rpc.events.ResultEvent;    
 8       [Bindable]    
 9           private var helloResult:String;      
10           private function input():void {    
11             inp.display(nam.text,sex.text,email.text);
12         }
13         
14        private function resultHandler(event:ResultEvent):void {    
15             helloResult=event.result as String;    
16         } 
17     ]]>   
18 </mx:Script>      
19      <mx:RemoteObject id="inp" destination="input" result="resultHandler(event)"/>       
20       
21         <mx:TextInput id="nam" x="275" y="54"/>
22         <mx:TextInput id="sex" x="275" y="102"/>
23         <mx:TextInput id="email" x="275" y="144"/>   
24         <mx:Label x="161" y="56" text="姓名:" fontSize="14"/>
25         <mx:Label x="161" y="104" text="性别:" fontSize="14"/>
26         <mx:Label x="161" y="146" text="邮箱:" fontSize="14"/>               
27         <mx:Button label = "Submit" click="input()" x="302" y="183"/>      
28         <mx:Panel x="185" y="243" width="250" height="200" layout="absolute" title="你输入的信息是" fontSize="14">
29                <mx:TextArea x="0" y="0" width="230" height="155" text="{helloResult}" editable="false"/>
30         </mx:Panel>
31      </mx:Application>    

代码没什么很重要的,应该看一下就能理解了。
运行效果如下:


再次提交,就不会有刷新的效果了。
这也就是我喜欢flex的地方。不过第一次加载的时候可能速度有点慢。

posted on 2009-04-11 14:48 duduli 阅读(2488) 评论(5)  编辑  收藏 所属分类: Flex

评论

# re: 【原创】flex in action (六)flex与后台Java进行交互(2) 2009-04-11 17:31 枯宽

顶一个~~
博主是做这方面的开发吗?  回复  更多评论   

# re: 【原创】flex in action (六)flex与后台Java进行交互(2) 2009-04-11 20:07 duduli

@枯宽
算是吧,工作难找,就只能努力学习啦  回复  更多评论   

# re: 【原创】flex in action (六)flex与后台Java进行交互(2) 2010-01-01 13:23 lifuhong

谢谢了,考走了
  回复  更多评论   

# re: 【原创】flex in action (六)flex与后台Java进行交互(2) 2010-04-04 14:10 pangchao

真的很感谢,现在正学习中~  回复  更多评论   

# re: 【原创】flex in action (六)flex与后台Java进行交互(2) 2010-04-04 14:57 pangchao

请问你有源码吗。给我发一份吧,pangchaoit@gamil.com 万分感谢  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航:
 
<2009年4月>
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

导航

统计

公告

welcome to my place.

常用链接

留言簿(5)

我参与的团队

随笔分类

随笔档案

新闻分类

石头JAVA摆地摊儿

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

@duduli