Slighty reformatted.
This commit is contained in:
@@ -9,19 +9,27 @@ import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class MyAgent extends Agent {
|
||||
protected void setup () {
|
||||
public class MyAgent extends Agent
|
||||
{
|
||||
|
||||
protected void setup()
|
||||
{
|
||||
displayResponse("Hello, I am " + getAID().getLocalName());
|
||||
addBehaviour(new MyCyclicBehaviour(this));
|
||||
//doDelete();
|
||||
}
|
||||
protected void takeDown() {
|
||||
|
||||
protected void takeDown()
|
||||
{
|
||||
displayResponse("See you");
|
||||
}
|
||||
public void displayResponse(String message) {
|
||||
public void displayResponse(String message)
|
||||
{
|
||||
JOptionPane.showMessageDialog(null,message,"Message",JOptionPane.PLAIN_MESSAGE);
|
||||
}
|
||||
public void displayHtmlResponse(String html) {
|
||||
|
||||
public void displayHtmlResponse(String html)
|
||||
{
|
||||
JTextPane tp = new JTextPane();
|
||||
JScrollPane js = new JScrollPane();
|
||||
js.getViewport().add(tp);
|
||||
@@ -36,16 +44,26 @@ public class MyAgent extends Agent {
|
||||
}
|
||||
}
|
||||
|
||||
class MyCyclicBehaviour extends CyclicBehaviour {
|
||||
class MyCyclicBehaviour extends CyclicBehaviour
|
||||
{
|
||||
MyAgent myAgent;
|
||||
public MyCyclicBehaviour(MyAgent myAgent) {
|
||||
|
||||
|
||||
public MyCyclicBehaviour(MyAgent myAgent)
|
||||
{
|
||||
this.myAgent = myAgent;
|
||||
}
|
||||
public void action() {
|
||||
|
||||
|
||||
public void action()
|
||||
{
|
||||
ACLMessage message = myAgent.receive();
|
||||
if (message == null) {
|
||||
if (message == null)
|
||||
{
|
||||
block();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
String ontology = message.getOntology();
|
||||
String content = message.getContent();
|
||||
int performative = message.getPerformative();
|
||||
|
||||
@@ -8,11 +8,14 @@ import jade.domain.FIPAAgentManagement.*;
|
||||
import java.net.*;
|
||||
import java.io.*;
|
||||
|
||||
public class ServiceAgent extends Agent {
|
||||
protected void setup () {
|
||||
public class ServiceAgent extends Agent
|
||||
{
|
||||
protected void setup ()
|
||||
{
|
||||
//services registration at DF
|
||||
DFAgentDescription dfad = new DFAgentDescription();
|
||||
dfad.setName(getAID());
|
||||
|
||||
//service no 1
|
||||
ServiceDescription sd1 = new ServiceDescription();
|
||||
sd1.setType("answers");
|
||||
@@ -21,12 +24,17 @@ public class ServiceAgent extends Agent {
|
||||
ServiceDescription sd2 = new ServiceDescription();
|
||||
sd2.setType("answers");
|
||||
sd2.setName("dictionary");
|
||||
|
||||
//add them all
|
||||
dfad.addServices(sd1);
|
||||
dfad.addServices(sd2);
|
||||
try {
|
||||
|
||||
try
|
||||
{
|
||||
DFService.register(this,dfad);
|
||||
} catch (FIPAException ex) {
|
||||
}
|
||||
catch (FIPAException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
|
||||
@@ -34,11 +42,15 @@ public class ServiceAgent extends Agent {
|
||||
addBehaviour(new DictionaryCyclicBehaviour(this));
|
||||
//doDelete();
|
||||
}
|
||||
protected void takeDown() {
|
||||
protected void takeDown()
|
||||
{
|
||||
//services deregistration before termination
|
||||
try {
|
||||
try
|
||||
{
|
||||
DFService.deregister(this);
|
||||
} catch (FIPAException ex) {
|
||||
}
|
||||
catch (FIPAException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user