📄 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; /** 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 price=jTextField1.getText(); String qty=jTextField2.getText(); String share = (String) jComboBox2.getSelectedItem(); String order= (String) jComboBox1.getSelectedItem(); try { this.beginBuy(share,qty,price,order); } 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 exitApplication(); }//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 = true; JButton startButton = new JButton(); AgentContext context = null; public void exec(AgentContext context) { this.setVisible(true); try { this.context = context; ZeusAgent zAgent = (ZeusAgent) context.Agent(); zAgent.addFactMonitor(this,1); ResourceDb resdb = this.context.ResourceDb(); validate(); show(); repaint(); } catch (Exception e) { e.printStackTrace(); } } public void beginBuy(String share, String qty, String price, String order) { System.out.println("\nAttempting to buy: " + share); System.out.println("My preferences: price= " + price); System.out.println("qty: " + qty); System.out.println("type of order: " + order); // 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 share, String price) { System.out.println("\nAttempting to buy: " + share); System.out.println("My preferences: price= " + price); /*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); */ } // 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); String id = currentFact.getValue("name"); System.out.println("name = " + id); } 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 + -