package client; //import agent.core.communication.Message; import server.Server; import server.TraderAgent; import jade.core.AID; import jade.core.Agent; import jade.core.Profile; import jade.core.ProfileImpl; import jade.core.Specifier; import jade.lang.acl.ACLMessage; import jade.util.Logger; import jade.util.leap.ArrayList; public class QIApplet extends java.applet.Applet { protected QI qi; private AppletAgentQI aqi; public static String jadeHostName; public static int jadePort; public static int appletContainerPort; public static final String APPLET_AGENT_NAME = "UI-Agent"; private jade.wrapper.AgentContainer appletContainer; private static Logger logger = Logger.getMyLogger(QI.class.getName()); /** Initializes the applet QIApplet */ public void init() { try { java.awt.EventQueue.invokeAndWait(new Runnable() { public void run() { initComponents(); initFrame(); jadeHostName = getParameter("jadeHostName"); System.out.println("jadeHostName: " + jadeHostName); jadePort = Integer.parseInt(getParameter("jadePort")); appletContainerPort = Integer.parseInt(getParameter("appletContainerPort")); createAppletAgent(); } }); } catch (Exception ex) { ex.printStackTrace(); } } /** This method is called from within the init() method to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // //GEN-BEGIN:initComponents private void initComponents() { setLayout(new java.awt.BorderLayout()); }// //GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables // End of variables declaration//GEN-END:variables private void initFrame() { qi = new QI(); qi.setVisible(true); qi.setEnabled(true); qi.setResizable(false); qi.setSize(1400, 1000); qi.setTitle("The SOLERES Query Interface"); } public void createAppletAgent() { Profile profile; Specifier specifier; Object object[]; jade.util.leap.List list; jade.core.Runtime runtime; AppletAgentQI agent; profile = new ProfileImpl(this.jadeHostName, this.jadePort, null); specifier = new Specifier(); object = new Object[1]; list = new ArrayList(1); object[0] = "http://" + this.jadeHostName + ":" + appletContainerPort + "/test"; specifier.setClassName("jade.mtp.http.MessageTransportProtocol"); specifier.setArgs(object); list.add(specifier); profile.setSpecifiers(profile.MTPS, list); runtime = jade.core.Runtime.instance(); this.appletContainer = runtime.createAgentContainer(profile); try { agent = new AppletAgentQI(this, null /*(TraderAgent) new Agent("Trader-Agent")*/); appletContainer.acceptNewAgent(this.APPLET_AGENT_NAME, agent).start(); if(this.logger.isLoggable(Logger.FINE)) { this.logger.log(Logger.FINE,"Applet agent created."); } aqi = agent; } catch(Exception exception) { if(this.logger.isLoggable(Logger.WARNING)) { this.logger.log(Logger.WARNING, exception.getMessage()); } } } }