import java.net.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.vecmath.*;
import javax.media.j3d.*;
import java.awt.*;

import com.sun.j3d.utils.universe.SimpleUniverse;
import com.sun.j3d.utils.universe.ViewingPlatform;
import com.sun.j3d.utils.applet.MainFrame;

import com.sun.j3d.utils.geometry.*;

public class TestBed extends Applet
{

  static public void main(String[] args)
  {
        System.out.println("in main");
        new MainFrame(new TestBed(), 300, 300);
  }

  TestBed()
  {
  }

  public void init()
  {
    setLayout(new BorderLayout());

    // Make the canvas.  Use our derived canvas to compute frame rate.
    GraphicsConfigTemplate3D template = new GraphicsConfigTemplate3D();
    GraphicsConfiguration gcfg =
              GraphicsEnvironment.getLocalGraphicsEnvironment().
              getDefaultScreenDevice().getBestConfiguration(template);
    Canvas3D canvas = new TestBedCanvas(gcfg);
    canvas.setSize(300, 300);
    add("Center", canvas);

    // Create the universe.
    SimpleUniverse universe = new SimpleUniverse(canvas);
    AudioDevice audioDev = universe.getViewer().createAudioDevice();

    // Create the main branch.
    BranchGroup mainBranch = new BranchGroup();

    // Put a color cube in the scene just for the "halibut".
    Transform3D xform = new Transform3D();
        xform.setTranslation(new Vector3f(0.0f, 0.0f, -10.0f));
    TransformGroup grp = new TransformGroup(xform);
        grp.addChild(new ColorCube());
    mainBranch.addChild(grp);

    // The sound.
    try
    {
      URL soundURL = new URL(getDocumentBase(), "Crickets.wav");
      MediaContainer soundMedia = new MediaContainer(soundURL);
      BackgroundSound sound = new BackgroundSound(soundMedia, 1.0f);
          sound.setEnable(true);
      Bounds bounds =
        new BoundingSphere(new Point3d(0.0,0.0,500000000.0), 0.1);
      sound.setLoop(-1);
      sound.setSchedulingBoundingLeaf(null);
      sound.setSchedulingBounds(bounds);
      mainBranch.addChild(sound);
    }
    catch ( MalformedURLException exc )
    {
      System.out.println("Could not open sound file!");
    }

    // Make the main branch live.
    universe.addBranchGraph(mainBranch);
  }
}

