good morning, i would like to create an array that contain a multiple instances of an agent (many agents that have a same behaviour), so i used netbeans to create firstly an agent management who create the others agents and draw a circle that represent every agent in a frame. this the code for the main agent:
package jade;
/**
*
* @author walid
*/
import jade.core.Agent;
import jade.core.Runtime;
import jade.core.ProfileImpl;
import jade.wrapper.*;
import javax.swing.JFrame;
import java.awt.Dimension;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jade.Agent1;
public class AgentEnvironement extends Agent{
private JFrame jFrame = null;
private Agent1 []tab;
@Override
protected void setup() {
try {
getJFrame().setVisible(true);
} catch (StaleProxyException ex) {
Logger.getLogger(AgentEnvironement.class.getName()).log(Level.SEVERE, null, ex);
}
}
public JFrame getJFrame() throws StaleProxyException {
if (jFrame == null) {
jFrame = new JFrame();
jFrame.setSize(new java.awt.Dimension(500,350));
Dimension tailleEcran =Toolkit.getDefaultToolkit().getScreenSize();
int largeurEcran = tailleEcran.width;
int hauteurEcran = tailleEcran.height;
jFrame.setLocation((largeurEcran-500)/2,(hauteurEcran-350)/2);
jFrame.setTitle("Environement des agents rumeurs.");
jFrame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
//jFrame.setContentPane(getJContentPane());
Runtime rt = Runtime.instance();
// Création du profil par défault
ProfileImpl p = new ProfileImpl(false);
AgentContainer container =rt.createMainContainer(p);
// Agent controleur pour permettre la création des agents
AgentController Agent=null;
Agent = container.createNewAgent("Agent1", "jade.Agent1", null);
Agent.start();
}
return jFrame;
}
}
and this the code for the agent class that i would like to create many instance of him package jade;
import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.CyclicBehaviour;
import jade.lang.acl.ACLMessage;
/**
*
* @author walid
*/
public class Agent1 extends Agent {
/**
*/
@Override
public void setup() {
addBehaviour(new comportement());
}
class comportement extends CyclicBehaviour {
public void action() {
System.out.println ("ready");
}
}
public static void main(String[] args) {
}
}
honestly i'm not good in java programming and if someone can help me i will be very pleasure.
Create an array of agents???? I'm not sure what that means but if you want to create multiple agents use a for loop and a counter to increment the name.
this should create multiple agents of type jade.Agent1 eg for agentmax=10
Agent1 (Type jade.Agent1)
Agent2 (Type jade.Agent1)
Agent3 (Type jade.Agent1)
....
Agent10 (Type jade.Agent1)
Notice that in
The first field is the name of the instance of the agent The second field is the agent class