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