1.java
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;
}
}
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
Java代码
<?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>
<?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
Java代码
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;
[Bindable]
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>
Java+Flex整合应用简单示例 (mx:RemoteObject)
最新推荐文章于 2025-02-17 10:33:35 发布