如何在同一文本字段中输入许多代理

时间:2018-04-20 09:37:51

标签: java swing user-interface pug agent

在同一文本字段中创建多个代理类型的最简单方法是什么,我使用的线程在构造函数中传递jtextarea作为参数,但我不知道如何使用jade代理执行此操作。 任何想法!!!

这是我的代码:

第一课:

    public class first extends Agent {
@Override
protected void setup(){

  addBehaviour(new OneShotBehaviour(){
        @Override
        public void action() {
            System.out.println("enter a number :") ;// entre a number to transmit to agent second
            Scanner in=new Scanner(System.in);
            int n =in.nextInt();
ACLMessage msg=new ACLMessage(ACLMessage.INFORM);
            msg.setContent(""+n);
            msg.addReceiver(new AID("second",AID.ISLOCALNAME));
            send(msg);//send the msg 
        }});
    addBehaviour(new CyclicBehaviour() {
        @Override
        public void action(){
            ACLMessage msg1=receive();
            if(msg1!=null){  
           System.out.println("msg receiv :"+msg1.getContent());// print the msg received (here i want to print it in jtextarea)
            }else block();}
    });
}}
第二课:

public class second extends Agent {

@Override
protected void setup(){

    addBehaviour(new CyclicBehaviour() {
        @Override
        public void action(){
            ACLMessage msg=receive();
            if(msg!=null){
              System.out.println("number receiv :"+msg.getContent());// print the msg received (here i want to print it in jtextarea)
             ACLMessage msg1=msg.createReply();
            msg1.setContent(""+Integer.parseInt(msg.getContent())*Integer.parseInt(msg.getContent()));
            send(msg1);
            }else block();
        }
}); 
}
}

主要课程:

public class Typing_agents {


   public static void main(String[] args) throws StaleProxyException, InterruptedException {


        Runtime rt = Runtime.instance();
        Profile p = new ProfileImpl(); 
        p.setParameter(Profile.GUI, "true");
        ContainerController cc = rt.createMainContainer(p);
           AgentController first ;
                   AgentController second ;
           first = cc.createNewAgent("first","typing_agents.first",null);
                   second = cc.createNewAgent("second","typing_agents.second",null); 
            first.start();
                second.start();              
    }
}

0 个答案:

没有答案