如何 link JavaFx 与代理的 Jade 框架

how to link JavaFx with Jade framework for agent

我无法将 javaFx 与代理 class 链接,我想将 javafx 应用程序的实例值传递给代理 class 以与 javaFx 的 GUI 和反向代理交互 class 我想将当前代理的实例对象传递给 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 将对象传递给代理,并使用 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();
            }
        }
    });
}