import mkgray.gui.*;
import java.awt.*;
import java.io.*;
import java.util.*;

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

  public static void main(String s[]){
    new GraphAccel();
  }

  GraphAccel() {
    Thread runthis = new Thread(this);
    runthis.start();
    while(true){
     if((sg != null) && (f != null)){
       System.out.println("repainting...\n");
	f.repaint();
	sg.repaint();
      }
	try { Thread.sleep(500); } catch (Exception e) { }
    }
  }

  public void run() {
    int value;
    f = new Frame();
    f.add(sg = new SimpleGraph());
    f.setBounds(0,0,300,300);
    f.pack();
    f.doLayout();
    f.show();
    sg.sliding(true);
    sg.windowWidth(100.0);
    sg.tickSeperation(10.0);
    int ct = 0;
    int n = 0;
    double np, pp;
    Random rand = new Random();
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    value = 0;
    System.out.println("Initialized");
    while(true) {
	String str = new String("");
      try {
	System.out.println("Reading line...");
	value = Integer.parseInt(str= br.readLine());
      } catch (Exception e) { }
      System.out.println("Got "+value+" ("+str+")");
      try { Thread.sleep(10); } catch (Exception e) {}
      sg.addPoint(ct++, value);
      sg.repaint();
    }
  }
}

