import javax.swing.*; import java.awt.*; import java.awt.event.*; import javax.swing.KeyStroke; import java.net.*; import java.io.*; import java.text.*; import javax.swing.text.*; import java.awt.Toolkit; import java.util.Locale; import javax.swing.JTable; import javax.swing.table.AbstractTableModel; import java.util.*; //Built by Josh Moss jmmoss@cs.uchicago.edu public class basictrade extends JApplet implements Serializable, ActionListener { private boolean DEBUG = true; public final static int ONE_SECOND=1000; private Timer timer; String value = "abcdef"; private JLabel CurrentPLf; private JButton buybutton; public void writeOrder(URLConnection connection, String value) { try { connection.setUseCaches(false); connection.setRequestProperty("CONTENT_TYPE","application/octet-stream"); connection.setDoInput(true); ObjectOutputStream os = new ObjectOutputStream(connection.getOutputStream()); connection.setDoOutput(true); System.err.println("Writing Order Object."); os.writeObject(value); } catch (IOException e) { System.err.println(e.getMessage()); } } public void readOrder(URLConnection connection) { try { ObjectInputStream is = new ObjectInputStream(connection.getInputStream()); System.err.println("Waiting for Response"); value = (String)is.readObject(); is.close(); } catch (IOException e) { System.err.println(e.getMessage()); System.err.println(e);} catch (ClassNotFoundException ce) { System.err.println(ce.getMessage()); } } public void actionPerformed(ActionEvent e){ try { System.err.println("Opening Connection."); URL url =new URL("http://euronymous.cs.uchicago.edu:4080"+"/usr/home/tlucas/httpd/servlets/CubsServlet"); URLConnection con = url.openConnection(); writeOrder(con, value); readOrder(con); CurrentPLf.setText(value); } catch (MalformedURLException mue) { System.err.println(mue.getMessage()); } catch (Exception ef) { System.err.println(ef.getMessage()); } } class MyTableModel extends AbstractTableModel { final String[] columnNames = {"Buy/Sell","Amount(EUR)","Rate", "ContraValue(USD)", "CounterPty"}; final Object[][] data = { {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)}, {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)}, {"Kathy", "Walrath", "Chasing toddlers", new Integer(2), new Boolean(false)}, {"Mark", "Andrews", "Speed reading", new Integer(20), new Boolean(true)}, {"Angela", "Lih", "Teaching high school", new Integer(4), new Boolean(false)} }; public int getColumnCount() { return columnNames.length; } public int getRowCount() { return data.length; } public String getColumnName(int col) { return columnNames[col]; } public Object getValueAt(int row, int col) { return data[row][col]; } } public void init() { //Make the layoutmanager grid Container contentPane= getContentPane(); contentPane.setLayout(new GridLayout(0,1)); //Init a timer timer = new Timer(ONE_SECOND, new ActionListener() { public void actionPerformed(ActionEvent evt) {} }); timer.start(); //Initialize more variables //Trader Vars double position, averagePrice, defaultStopPrice; int intID; String strName; //Order Vars int amount; double price; boolean isBuy; String Type, status; //LogVars String counterParty; MyTableModel myModel = new MyTableModel(); JTable table= new JTable(myModel); JTable openOrderTable= new JTable(); //Large scale constructs JPanel topPanel=new JPanel(); JScrollPane bottomPanel=new JScrollPane(table); JScrollPane openOrderPanel=new JScrollPane(openOrderTable); //Authentication Items JLabel logon = new JLabel("login:"); JTextField logonf=new JTextField(10); JLabel passwd = new JLabel("password:"); JPasswordField passwdf=new JPasswordField(10); //Top Panel Items Line 2 JLabel QPosition=new JLabel("Queue Position:"); JLabel QPositionf=new JLabel(); JLabel currentPosition = new JLabel("Current Position:"); JLabel currentPositionf = new JLabel(); //Top Panel Items Line 3 JLabel avgPositionRate = new JLabel("Avg. Position Cost:"); JLabel avgPositionRatef = new JLabel(); JLabel currentMarketRate = new JLabel("Current Mkt Rate:"); JLabel currentMarketRatef = new JLabel(); //Top Panel Items Line 4 JLabel CurrentPL=new JLabel("Current P/L (USD):"); CurrentPLf=new JLabel(); JLabel maxPosSLRate = new JLabel("MaxStopLoss Rate:"); JLabel maxPosSLRatef = new JLabel(); JLabel currentPositionPLRate= new JLabel("Current Pos. P/L Rate:"); JLabel currentPositionPLRatef= new JLabel(); JLabel tradeSize = new JLabel("Trade Size(EUR):"); JTextField tradeSizef = new JTextField(12); JLabel tradeRate= new JLabel("Trade Rate:"); JTextField tradeRatef = new JTextField(8); buybutton = new JButton("Buy"); JButton sellbutton= new JButton("Sell"); JButton clearbutton= new JButton("Clear"); JButton updatebutton = new JButton("Update"); //Bottom Panel Items //Large-scale constructs topPanel.setLayout(new GridLayout(0,4)); contentPane.add(topPanel); contentPane.add(bottomPanel); contentPane.add(openOrderPanel); //Authentication: Line 1 topPanel.add(logon); topPanel.add(logonf); topPanel.add(passwd); topPanel.add(passwdf); passwdf.setEchoChar('*'); //Market and Position Information-Top Panel //Line 2 topPanel.add(QPosition); topPanel.add(QPositionf); topPanel.add(currentMarketRate); topPanel.add(currentMarketRatef); //Line 3 topPanel.add(currentPosition); topPanel.add(currentPositionf); topPanel.add(currentPositionPLRate); topPanel.add(currentPositionPLRatef); //Line 4 topPanel.add(avgPositionRate); topPanel.add(avgPositionRatef); topPanel.add(CurrentPL); topPanel.add(CurrentPLf); //Line 5 topPanel.add(tradeSize); topPanel.add(tradeSizef); topPanel.add(tradeRate); topPanel.add(tradeRatef); topPanel.add(updatebutton); topPanel.add(buybutton); topPanel.add(sellbutton); topPanel.add(clearbutton); //Button Handling buybutton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); sellbutton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); clearbutton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // tradeSizef.setText("0"); //tradeAmtf.setText=("0"); } }); } }