package exemple.jade;
import com.sun.istack.internal.logging.Logger;
import jade.core.AID;
import jade.core.ProfileImpl;
import jade.domain.FIPAAgentManagement.DFAgentDescription;
import jade.gui.GuiEvent;
import jade.wrapper.AgentController;
import java.util.logging.Level;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.lang.*;
/**
*
* @author HP
*/
public class Agent1 extends jade.gui.GuiAgent {
transient protected AgentInetrface Interface1;
public Agent1() {
this.Interface1 = new AgentInetrface(this);
}
protected void setup() {
// Printout a welcome message
Interface1 = new AgentInetrface(this);
Interface1.setVisible(true);
System.out.println("Hello! Agent fatima " + getAID().getName() + " is ready.");
String localname = "Fatima";
AID id = new AID(localname, AID.ISLOCALNAME);
// Enregistrement aupres du directory facilitator
DFAgentDescription dfd = new DFAgentDescription();
dfd.setName(id);
}
@Override
protected void onGuiEvent(GuiEvent ge) {
}
public void req(String M) {
addBehaviour(new Envoi(M));
}
public class Envoi extends jade.core.behaviours.OneShotBehaviour {
String message;
public Envoi(String M) {
this.message = M;
}
@Override
public void action() {
System.out.println(message);
}
}
public static void main(String[] args) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException ex) {
Logger.getLogger(Agent1.class.getName()).log(Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
Logger.getLogger(Agent1.class.getName()).log(Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
Logger.getLogger(Agent1.class.getName()).log(Level.SEVERE, null, ex);
} catch (UnsupportedLookAndFeelException ex) {
Logger.getLogger(Agent1.class.getName()).log(Level.SEVERE, null, ex);
}
try {
jade.core.Runtime runtime = jade.core.Runtime.instance();
ProfileImpl profileImpl = new ProfileImpl(false);
profileImpl.setParameter(ProfileImpl.MAIN_HOST, "localhost");
jade.wrapper.AgentContainer agentContainer = runtime.createAgentContainer(profileImpl);
AgentController agentController = agentContainer.createNewAgent("agg", "exmple.Agent1", null);
agentController.start();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
}
Partager