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