import jade.core.Agent;
import jade.core.behaviours.*;
public class Simple0 extends Agent
{
protected void setup()
{
addBehaviour( new B1( this ) );
}
}
class B1 extends SimpleBehaviour
{
public B1(Agent a) { //这个函数B1是干什么的?参见前面agent class的典型结构
super(a);
}
public void action()
{
System.out.println( "Hello World! My name is " +
myAgent.getLocalName() ); //这里的myAgent是怎么来的?
}
private boolean finished = false;
public boolean done() { return finished; }
} //End class B1
/*****************************************************************
Simple1.java: Minimal agent with anonymous behaviour
*****************************************************************/
import jade.core.Agent;
import jade.core.behaviours.*;
public class Simple1 extends Agent
{
protected void setup()
{
addBehaviour( // -------- Anonymous SimpleBehaviour
new SimpleBehaviour( this )
{
int n=0;
public void action()
{
System.out.println( "Hello World! My name is " +
myAgent.getLocalName() );
n++;
}
public boolean done() { return n>=3; }
}
);
} // --- setup ---
} // --- class Simple1
上面两个程序,一个不停地打印,一个打印三行,不过第二个程序即使不在打印,也不意味着程序结束了,这是因为:1、agent依然存在 2、JADE environment依然存在,它在等待着要和其他agent交流。