如何将JavaFx与Jade框架链接到代理
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将JavaFx与Jade框架链接到代理相关的知识,希望对你有一定的参考价值。
我无法将javaFx与代理类链接,我想将javafx应用程序的实例值传递给代理类,以便与javaFx的GUI交互,而Inverse From代理类我想将当前代理的实例对象传递给JavaFx应用程序来做一些东西
public class ClientAgent extends Agent {
@Override
protected void setup() {
}}
public class ClientController extends Application {
private ClientAgent clientAgent;
@Override
public void start(Stage primaryStage) throws Exception{
Group flowPane=new Group();
JFXButton jfxButton=new JFXButton("Login");
flowPane.getChildren().add(jfxButton);
primaryStage.setTitle("Hello World");
primaryStage.setScene(new Scene(flowPane, 600, 400));
primaryStage.show();
jfxButton.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
}
});
}
public void setClientAgent(ClientAgent clientAgent) {
this.clientAgent = clientAgent;
}
}
public class ClientContainer {
public static void main(String [] args) {
try {
Runtime runtime=Runtime.instance();
ProfileImpl profile=new ProfileImpl(false);
profile.setParameter(Profile.MAIN_HOST,"localhost");
AgentContainer agentContainer=runtime.createAgentContainer(profile);
AgentController agentController=agentContainer.createNewAgent("client", ClientAgent.class.getName(),new Object[] {});
agentController.start();
} catch (StaleProxyException e) {
e.printStackTrace();
} catch (ControllerException e) {
e.printStackTrace();
}
}
}
答案
您可以尝试使用putO2AObject将对象传递给agent和jade.util.Event以传回数据。例如
AgentController agentController = ...;
jade.util.Event event = new Event(-1, this, new SomeObject());
agentController.putO2AObject(event, AgentController.ASYNC);
Object someObjectFromAgent = event.waitUntilProcessed(10 * 60 * 1000);
在代理商你应该
protected void setup(){
setEnabledO2ACommunication(true, 0);
addBehaviour(new CyclicBehaviour(this){
public void action(){
Object info = myAgent.getO2AObject();
if (info != null){
// do something with Event
event.notifyProcessed(new SomeObjectFromAgent());
}else{
block();
}
}
});
}
以上是关于如何将JavaFx与Jade框架链接到代理的主要内容,如果未能解决你的问题,请参考以下文章