⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 segui.java~

📁 用Multi-Agent平台Zeus开发的一个功能完整的开源安全股票交易系统
💻 JAVA~
字号:
/* * SEgui.java * * Created on July 4, 2002, 12:24 PM *///package projet;import java.awt.*;import java.awt.event.*;import java.util.*;import java.io.*;import javax.swing.*;import java.lang.*;import zeus.util.*;import zeus.concepts.*;import zeus.agents.*;import zeus.actors.*;import zeus.actors.event.*;import zeus.gui.*;/** * * @author  naudark */public class SEgui extends javax.swing.JFrame implements ZeusExternal, FactMonitor {    int share;        double purchaseOffer[]=new double[]{ 10.0, 10.8,9.7,10.2};        double sellOffer[]=new double[]{ 10.1,9.4,9.8,9.9,9.5};        int top;        int bottom;        int current;        boolean frameSizeAdjusted = false;    JButton startButton = new JButton();    AgentContext context = null;    mazeView mazeGui = null;    mazeModel mazeInUse = null;        /** Creates new form SEgui */    public SEgui() {        initComponents();    }    /** This method is called from within the constructor to     * initialize the form.     * WARNING: Do NOT modify this code. The content of this method is     * always regenerated by the Form Editor.     */    private void initComponents() {//GEN-BEGIN:initComponents        jComboBox1 = new javax.swing.JComboBox();        jTextField1 = new javax.swing.JTextField();        jLabel1 = new javax.swing.JLabel();        jLabel2 = new javax.swing.JLabel();        jLabel3 = new javax.swing.JLabel();        jTextField2 = new javax.swing.JTextField();        jTextField3 = new javax.swing.JTextField();        jList1 = new javax.swing.JList();        jList2 = new javax.swing.JList();        jList3 = new javax.swing.JList();        jList4 = new javax.swing.JList();        jLabel4 = new javax.swing.JLabel();        jTextField4 = new javax.swing.JTextField();                getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());                setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);        setResizable(false);        addWindowListener(new java.awt.event.WindowAdapter() {            public void windowClosing(java.awt.event.WindowEvent evt) {                exitForm(evt);            }        });                jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Axa", "Aventis", "Accenture", "Bouygues", "Dassault" }));        jComboBox1.addActionListener(new java.awt.event.ActionListener() {            public void actionPerformed(java.awt.event.ActionEvent evt) {                jComboBox1ActionPerformed(evt);            }        });                getContentPane().add(jComboBox1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 30, 280, -1));                jTextField1.setEditable(false);        jTextField1.setText("10.7");        getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 90, -1, -1));                jLabel1.setText("current");        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 90, -1, -1));                jLabel2.setText("top");        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 120, -1, -1));                jLabel3.setText("bottom");        getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 150, -1, -1));                jTextField2.setEditable(false);        jTextField2.setText("11");        getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 120, -1, -1));                jTextField3.setEditable(false);        jTextField3.setText("10.3");        getContentPane().add(jTextField3, new org.netbeans.lib.awtextra.AbsoluteConstraints(70, 150, -1, -1));                jList1.setBorder(new javax.swing.border.TitledBorder("Purchase Offer"));        jList1.setModel(new javax.swing.AbstractListModel() {            String[] strings = { "10.2", "9.5", "11.2", "10", "10.7" };            public int getSize() { return strings.length; }            public Object getElementAt(int i) { return strings[i]; }        });        getContentPane().add(jList1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 220, 120, 110));                jList2.setBorder(new javax.swing.border.TitledBorder("Sell Offer"));        jList2.setModel(new javax.swing.AbstractListModel() {            String[] strings = { "11.3", "11", "10.7", "13.4", "12" };            public int getSize() { return strings.length; }            public Object getElementAt(int i) { return strings[i]; }        });        getContentPane().add(jList2, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 220, 120, 110));                jList3.setBorder(new javax.swing.border.TitledBorder("qty"));        jList3.setModel(new javax.swing.AbstractListModel() {            String[] strings = { "100", "300", "1400", "500", "450" };            public int getSize() { return strings.length; }            public Object getElementAt(int i) { return strings[i]; }        });        getContentPane().add(jList3, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 220, -1, 110));                jList4.setBorder(new javax.swing.border.TitledBorder("qty"));        jList4.setModel(new javax.swing.AbstractListModel() {            String[] strings = { "200", "800", "2000", "750", "200" };            public int getSize() { return strings.length; }            public Object getElementAt(int i) { return strings[i]; }        });        getContentPane().add(jList4, new org.netbeans.lib.awtextra.AbsoluteConstraints(320, 220, -1, 110));                jLabel4.setText("variation");        getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(170, 90, -1, -1));                jTextField4.setEditable(false);        jTextField4.setText("jTextField4");        getContentPane().add(jTextField4, new org.netbeans.lib.awtextra.AbsoluteConstraints(240, 90, -1, -1));                pack();    }//GEN-END:initComponents    private void jComboBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBox1ActionPerformed        // Add your handling code here:    }//GEN-LAST:event_jComboBox1ActionPerformed    /** Exit the Application */    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm        System.exit(0);    }//GEN-LAST:event_exitForm      public void exec(AgentContext context) {        this.setVisible(true);        try {            mazeInUse = new mazeModel();            mazeGui = new mazeView(mazeInUse);            //mazeGui.addMouseListener(mazeGui);            //mazeGui.addMouseMotionListener(mazeGui);                        this.context = context;            ZeusAgent zAgent = (ZeusAgent) context.Agent();            zAgent.addFactMonitor(this,1);            ResourceDb resdb = this.context.ResourceDb();            //mazeGui.setBackground(Color.white);            //mazeGui.setForeground(Color.white);            getContentPane().add("Center", mazeGui);            //mazeGui.setVisible(true);            validate();            //show();            //repaint();        }        catch (Exception e) { e.printStackTrace(); }    }            // factAccessed is left unimplemented    public void factAccessedEvent(FactEvent fe) {;}        // but we implement factAdded event to get some behavior in terms    // of referencing the model (which is external to zeus)    // and telling the zeus agent about it    public void factAddedEvent(FactEvent fe) {        Fact currentFact = fe.getFact();        String agentName = context.whoami();        String factType = currentFact.getType();        System.out.println("Fact = " + factType);        if (factType.equals("thisTrade")) {            // the trader connected to this proxy asks if it can trade in            // the Stock Exchange. This agent (Euronext) must decide what to do.                        // first step is to determine the contents of the trade            String purchase = currentFact.getValue("purchase");            String sell = currentFact.getValue("sell");            String id = currentFact.getValue("id");            boolean pBool = purchase.equals("true");            boolean sBool = sell.equals("true");            try {                Thread.sleep(30); // pause to prevent everything happening too quickly            }            catch (Exception e) {;}                        // now invoke a function that tests whether it is a legal trade, and enacts it if it is            // as a side effect the obstacles around the agent are asserted in the            // fact database, as is a fact indicating if the move made was legal or not            // this will trigger more behaviour in the agent.         //move(id, nBool, eBool, sBool, wBool);            // a message should now have been sent to the originating agent            // telling it what new obstacles lie in it's path!            ResourceDb rdb = context.ResourceDb();            rdb.del(currentFact);        }        else if (factType.equals("agentsName")) {            // new agent joining the Stock Exchange - determine its initial position            startButton.setEnabled(true);                        String id = currentFact.getValue("name");            jLabel1.setText(id);            repaint();                        /*int r = 0, c = 0;// mettre ici les caracteristiques d'achat ou de vente            mazeInUse.registerAgent(id, c, r);                        mazeGui.repaint();            OntologyDb ont = context.OntologyDb();            Fact obst = ont.getFact(Fact.FACT, "obstacle");            obst.setValue("north",mazeInUse.northVal(id));            obst.setValue("east",mazeInUse.eastVal(id));            obst.setValue("south",mazeInUse.southVal(id));            obst.setValue("west",mazeInUse.westVal(id));            obst.setValue("id", id);            // add it to the fact db            ResourceDb rdb = context.ResourceDb();            rdb.add(obst);            System.out.println("Added an obstacle");             */        }        else System.out.println("fact added and detected");    }        public void factDeletedEvent(FactEvent fe) {;}    public void factModifiedEvent(FactEvent fe) {;}    /**    * @param args the command line arguments    */    public static void main(String args[]) {        new SEgui().show();    }    // Variables declaration - do not modify//GEN-BEGIN:variables    private javax.swing.JComboBox jComboBox1;    private javax.swing.JTextField jTextField1;    private javax.swing.JLabel jLabel1;    private javax.swing.JLabel jLabel2;    private javax.swing.JLabel jLabel3;    private javax.swing.JTextField jTextField2;    private javax.swing.JTextField jTextField3;    private javax.swing.JList jList1;    private javax.swing.JList jList2;    private javax.swing.JList jList3;    private javax.swing.JList jList4;    private javax.swing.JLabel jLabel4;    private javax.swing.JTextField jTextField4;    // End of variables declaration//GEN-END:variables}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -