FileDocCategorySizeDatePackage
MYOSM.javaAPI DocExample2371Mon Nov 09 12:45:48 GMT 1998None

MYOSM

public class MYOSM extends JFrame implements Runnable

Fields Summary
Stock[]
market
boolean
monitor
Random
rg
Thread
runner
Constructors Summary
public MYOSM()


    
    // not meant to be shown as a real frame
    super("Thread only version . . .");
    runner = new Thread(this);
    runner.start();
  
public MYOSM(boolean monitorOn)

    super("Stock Market Monitor");
    setSize(400, 100);
    addWindowListener(new BasicWindowMonitor());
    monitor = monitorOn;

    getContentPane().add(new JLabel("Trading is active.  " + 
          "Close this window to close the market."), 
          BorderLayout.CENTER);
    runner = new Thread(this);
    runner.start();
  
Methods Summary
public StockgetQuote(int index)

    return market[index];
  
public java.lang.String[]getSymbols()

    String[] symbols = new String[market.length];
    for (int i = 0; i < market.length; i++) {
      symbols[i] = market[i].symbol;
    }
    return symbols;
  
public static voidmain(java.lang.String[] args)

    MYOSM myMarket = new MYOSM(args.length > 0);
    myMarket.setVisible(true);
  
public voidrun()

    while(true) {
      int whichStock = Math.abs(rg.nextInt()) % market.length;
      double delta = rg.nextDouble() - 0.4;
      market[whichStock].update(delta);
      if (monitor) {
        market[whichStock].print();
      }
      try {
        Thread.sleep(1000);
      }
      catch(InterruptedException ie) {
      }
    }