Ejemplo n.º 1
0
  public TreeViewer(String title, int ulx, int uly, int pw, int ph) {
    super(title, ulx, uly, pw, ph);

    // code to initialize instance variables before animation begins:
    // ------------------------------------------------------------------

    state = "regular";

    spread = 1;
    levelHeight = 10; // 10 levels for the camera region height

    tree = new SackBST();
    String fileName = FileBrowser.chooseFile(true);

    try {
      Scanner input = new Scanner(new File(fileName));
      String s;

      while (input.hasNext()) {
        s = input.nextLine();
        if (s != null) {
          tree.add(s);
        }
      }

      input.close();
    } catch (Exception e) {
      System.out.println("File load failed");
      System.exit(1);
    }

    // code to finish setting up entire window:
    // ------------------------------------------------------------------

    setBackgroundColor(new Color(128, 128, 200));

    // code to set up camera(s)
    // ------------------------------------------------------------------

    cameras.add(new Camera(10, 50, camw, camh, 0, 100, 0, new Color(255, 200, 255)));

    cameras.add(new Camera(10, 50 + camh + 10, camw, 20, 0, 100, 0, new Color(255, 255, 255)));

    // ------------------------------------------------------------------
    // start up the animation:
    super.start();
  }