简体   繁体   English

如何将JavaFx与Jade框架进行代理连接

[英]how to link JavaFx with Jade framework for agent

i can not linked javaFx with agent class , i want to pass the instance value of javafx application to agent class for interacting with GUI of javaFx and the Inverse From agent class i want to pass the instance object of current agent to JavaFx application to do some stuff 我无法将javaFx与代理类链接在一起,我想将javafx应用程序的实例值传递给代理类,以便与javaFx的GUI和Inverse From agent类进行交互,我想将当前代理的实例对象传递给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();
    }

}

} }

You can try to use putO2AObject to pass objects to agent and jade.util.Event to pass data back. 您可以尝试使用putO2AObject将对象传递给代理,并使用jade.util.Event将数据传递回。 For example 例如

AgentController agentController = ...;
jade.util.Event event = new Event(-1, this, new SomeObject());
agentController.putO2AObject(event, AgentController.ASYNC);
Object someObjectFromAgent = event.waitUntilProcessed(10 * 60 * 1000);

In an agent you should 在代理中,您应该

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();
            }
        }
    });
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM