?? projetdea.java~
字號:
/* * projetDEA.java * * Created on July 3, 2002, 9:17 PM *///package Templates.SwingForms;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.fields.*;import zeus.gui.*;/** * * @author naudark */public class projetDEA extends javax.swing.JFrame implements ZeusExternal, FactMonitor{ int share; int transaction; int Order; int price; int quantity; int field5; AgentContext context = null; /** Creates new form projetDEA */ public projetDEA() { 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 buttonGroup1 = new javax.swing.ButtonGroup(); jlabel1 = new javax.swing.JLabel(); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); jLabel3 = new javax.swing.JLabel(); jComboBox1 = new javax.swing.JComboBox(); jComboBox2 = new javax.swing.JComboBox(); jButton1 = new javax.swing.JButton(); jTextField1 = new javax.swing.JTextField(); jTextField2 = new javax.swing.JTextField(); jLabel4 = new javax.swing.JLabel(); jLabel5 = new javax.swing.JLabel(); status = new javax.swing.JLabel(); getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout()); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); setTitle("Trader Interface"); setBackground(java.awt.Color.lightGray); setFocusableWindowState(false); setMaximizedBounds(new java.awt.Rectangle(300, 200, 400, 300)); addWindowListener(new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { exitForm(evt); } }); jlabel1.setText("share"); getContentPane().add(jlabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 110, 60, 20)); jRadioButton1.setSelected(true); jRadioButton1.setText("acheter"); buttonGroup1.add(jRadioButton1); getContentPane().add(jRadioButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 150, -1, -1)); jRadioButton2.setText("vendre"); buttonGroup1.add(jRadioButton2); getContentPane().add(jRadioButton2, new org.netbeans.lib.awtextra.AbsoluteConstraints(200, 150, -1, -1)); jLabel3.setText("type of order"); getContentPane().add(jLabel3, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 190, 100, -1)); jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "prix du marche", "a tout prix", "a cours limite", "a seuil de declenchement", "tout ou rien" })); jComboBox1.setToolTipText("Permet de choisir le type d'ordre d'achat ou de vente "); 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(110, 190, 150, -1)); jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "aventis", "accenture", "arcelor", "Axa", "Bouygues", "Orange" })); getContentPane().add(jComboBox2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 110, 150, -1)); jButton1.setText("execute"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 310, -1, -1)); jTextField1.setFocusCycleRoot(true); getContentPane().add(jTextField1, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 230, 100, -1)); jTextField2.setFocusCycleRoot(true); getContentPane().add(jTextField2, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 270, 100, -1)); jLabel4.setText("quantity"); getContentPane().add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 270, 70, -1)); jLabel5.setText("price"); getContentPane().add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(30, 230, 70, -1)); status.setText("connected to Euronext"); getContentPane().add(status, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 20, -1, -1)); pack(); }//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed String share=jTextField1.getText(); String price=jTextField2.getText(); try { this.beginBuy(share,price); } catch (Exception e) {} }//GEN-LAST:event_jButton1ActionPerformed 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 /** * @param args the command line arguments public static void main(String args[]) { new projetDEA().show(); } */ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup buttonGroup1; private javax.swing.JLabel jlabel1; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; private javax.swing.JLabel jLabel3; private javax.swing.JComboBox jComboBox1; private javax.swing.JComboBox jComboBox2; private javax.swing.JButton jButton1; private javax.swing.JTextField jTextField1; private javax.swing.JTextField jTextField2; private javax.swing.JLabel jLabel4; private javax.swing.JLabel jLabel5; private javax.swing.JLabel status; // End of variables declaration//GEN-END:variables boolean frameSizeAdjusted = false; JButton startButton = new JButton(); AgentContext context = null; mazeView mazeGui = null; mazeModel mazeInUse = null; 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(); } } public void beginBuy(String fruit, String ask) { System.out.println("\nAttempting to buy: " + fruit); System.out.println("My preferences: price= " + ask); // j'ai rajoute try { OntologyDb ont = context.OntologyDb(); // if the button is pushed then add a fact to the database triggering // the registration rule Fact fact = ont.getFact(Fact.FACT, "agentsName"); fact.setValue("name","Axa"); ResourceDb ResDb = context.ResourceDb(); ResDb.add(fact); } catch (Exception e ) {e.printStackTrace();} //jusqu'ici /*Fact fact = UI.agent.OntologyDb().getFact(Fact.VARIABLE, fruit); fact.setNumber(1); int now = (int)UI.agent.now(); Goal g = new Goal(UI.agent.newId("goal"), fact, now+time, ask, UI.agent.whoami(), (double)(now+time-0.5)); UI.agent.Engine().buy(g); */ } /*public void beginSell(String fruit, int ask, int time) { UI.display("\nAttempting to sell: " + fruit); UI.display("My preferences: price= " + ask + ", within " + time + " time-grains"); Fact fact = UI.agent.OntologyDb().getFact(Fact.VARIABLE, fruit); fact.setNumber(1); int now = (int)UI.agent.now(); Goal g = new Goal(UI.agent.newId("goal"), fact, now+time, ask, UI.agent.whoami(), (double)(0)); UI.agent.Engine().sell(g); } /* public void startAction() { System.out.println("Called startAction"); try { OntologyDb ont = context.OntologyDb(); // if the button is pushed then add a fact to the database that // triggers a rule initiating movement from the all the agents Enumeration allAgents = mazeInUse.agents.keys(); while (allAgents.hasMoreElements()) { Fact fact = ont.getFact(Fact.FACT,"moveMade"); fact.setValue("moved","true"); String thisAgentsName = (String)allAgents.nextElement(); fact.setValue("id",thisAgentsName); int now = (int) context.now(); Integer thisInt = new Integer(now); ResourceDb ResDb = context.ResourceDb(); ResDb.add(fact);} } catch (Exception e ) { e.printStackTrace(); } System.out.println("Set initial move"); } */ // factAccessed is left unimplemented public void factAccessedEvent(FactEvent fe) {;} public void factDeletedEvent (FactEvent fe) {;} public void factModifiedEvent(FactEvent fe) {;} public void factAddedEvent (FactEvent fe) { Fact currentFact = fe.getFact(); String factType = currentFact.getType(); System.out.println("Fact = " + factType); if (factType.equals("agentRegistered")) { status.setText("Registered with Maze"); status.repaint(); startButton.setEnabled(false); } if (factType.equals("thisMove")) { String dir = "nowhere"; if ((currentFact.getValue("north")).equals("true")) dir = "North"; if ((currentFact.getValue("south")).equals("true")) dir = "South"; if ((currentFact.getValue("east")).equals("true")) dir = "East"; if ((currentFact.getValue("west")).equals("true")) dir = "West"; status.setText("Moving: " + dir); status.repaint(); } if (factType.equals("mazeExited")) { status.setText("I have reached the Maze exit."); startButton.setEnabled(true); ResourceDb resdb = context.ResourceDb(); try { resdb.del(resdb.all("inMaze"));} catch (Exception e){ e.printStackTrace();} try { resdb.del(currentFact);} catch (Exception e) { e.printStackTrace();} status.repaint(); } } public void addNotify() { // Record the size of the window prior to calling parents addNotify. Dimension size = getSize(); super.addNotify(); if (frameSizeAdjusted) return; frameSizeAdjusted = true; // Adjust size of frame according to the insets and menu bar JMenuBar menuBar = getRootPane().getJMenuBar(); int menuBarHeight = 0; if (menuBar != null) menuBarHeight = menuBar.getPreferredSize().height; Insets insets = getInsets(); setSize(insets.left + insets.right + size.width, insets.top + insets.bottom + size.height + menuBarHeight); } void exitApplication() { try { int reply = JOptionPane.showConfirmDialog(this, "Do you want to terminate this Agent?", "Kill Environment Agent?", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE); if (reply == JOptionPane.YES_OPTION) { this.setVisible(false); // hide the Frame this.dispose(); // free the system resources System.exit(0); // close the application } } catch (Exception e) {} } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -