import java.awt.*;
import java.util.*;

public class TryGraph implements Runnable {
  Frame f;
  SimpleGraph sg;

  public static void main(String s[]){
    System.out.println("Creating trygraph\n");
    new TryGraph();
  }

  TryGraph() {
    System.out.println("Starting graph run\n");
    Thread runthis = new Thread(this);
    runthis.start();
    System.out.println("Started!\n");
//    while(true){
//      if((sg != null) && (f != null)){
//	f.repaint();
//	sg.repaint();
//      }
//    }
  }

  public void run() {
    System.err.println("Running");
    f = new Frame();
    f.add(sg = new SimpleGraph());
    f.setBounds(0,0,300,300);
    f.pack();
    f.doLayout();
    f.show();
    System.out.println("Starting...");
    sg.sliding(true);
    sg.windowWidth(75.0);
    sg.tickSeperation(10.0);
    sg.addPoint(0, 0);
    sg.addPoint(2, 1);
    sg.addPoint(3, 2);
    sg.addPoint(4, 3);
    sg.addPoint(5, 4);
    sg.addPoint(6, 5);
    int ct = 7;
    int n = 0;
    double np, pp;
    pp = 50;
    Random rand = new Random();
    while(true) {
      try { Thread.sleep(200); } catch (Exception e) {}
      n = 0;
      np = pp + ((rand.nextDouble()*10)-5);
      pp = np;
      sg.addPoint(ct++, Runtime.getRuntime().totalMemory()-
		  Runtime.getRuntime().freeMemory());
      sg.repaint();
      f.repaint();
      System.out.println("Repainted\n");
    }
  }
}

