lin_yike 发表于 2013-2-3 12:21:52

Java+Flex整合应用简单示例(mx:RemoteObject)

1.java
package com;public class LoginDemo {public String validate(String username,String password){String message ="login failed!";if(username.equals("lin")&&password.equals("lin")){message = "login successed!";}return message;}}

2.remoting-config.xml

<?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="login">    <properties>    <source>com.LoginDemo</source>    </properties>      </destination>    </service>


3.mxml

<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"><mx:Script><!var returnValue:String;var username1:String;var password1:String;function sendRequest():void{username1=username.text;password1=password.text;ro.validate(username1,password1);ro.addEventListener(ResultEvent.RESULT,results);}function results(event:ResultEvent):void{returnValue=event.result as String;}function faultHandler(event:FaultEvent):void{Alert.show(event.fault.toString());}]]></mx:Script><mx:RemoteObject id="ro" destination="login" fault="faultHandler(event)"></mx:RemoteObject><mx:Panel height="400" width="400" layout="absolute" title="用户登录"><mx:Label x="50" y="50" text="用户名" width="50"></mx:Label><mx:Label x="50" y="75" text="密码" width="50"></mx:Label><mx:TextInput id="username" x="75" y="50"/><mx:TextInput id="password" x="75" y="75"/><mx:Button x="50" y="100" label="登录" click="sendRequest()"/><mx:Label x="50" y="130" text="{returnValue}"/></mx:Panel></mx:Application>
页: [1]
查看完整版本: Java+Flex整合应用简单示例(mx:RemoteObject)