import java.applet.Applet;
import java.awt.BorderLayout;
import java.awt.Frame;
import java.awt.event.*;
import java.awt.*;
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.applet.MainFrame;
import com.sun.j3d.utils.image.TextureLoader;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import com.sun.j3d.utils.behaviors.mouse.*;
import java.util.Enumeration;
import java.awt.AWTEvent;


//控制集装箱的起吊与卸载
class loadAndUnloadBehavior extends Behavior
implements ActionListener {
      public static boolean bLoad=false;
       private WakeupCriterion criterion;
    // create a new AWTInteractionBehavior
    public  loadAndUnloadBehavior() {}
	
    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this, 	
 				     MouseEvent.MOUSE_CLICKED);
 	 
 	 	 
	wakeupOn(criterion);
    }

   
    public void processStimulus(Enumeration criteria) {
        bLoad=!bLoad;
       	
	
	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}

//控制吊钩向下运动
class hookMoveDownBehavior extends Behavior
implements ActionListener {

    private TransformGroup targetRope;
    private Transform3D targetRope3D = new Transform3D();
    private TransformGroup targetHook;
    private Transform3D targetHook3D = new Transform3D();
    private TransformGroup targetAssembleBox;
    private Transform3D targetAssembleBox3D=new Transform3D();
    private double yScale=1.0;
	    private double x=0.0;
	    private double y=0.0;
	    private double z=0.0;
	    private double x1=0.0;
	    private double y1=0.0;
	    private double z1=0.0;
	    
    private WakeupCriterion criterion;
    
    // create a new AWTInteractionBehavior
    public  hookMoveDownBehavior(TransformGroup hook,TransformGroup rope,TransformGroup assembleBox) {
	this.targetHook = hook;
	this.targetRope=rope;
	 this.targetAssembleBox=assembleBox;   }

    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this,
 					     MouseEvent.MOUSE_CLICKED);
	wakeupOn(criterion);
    }

    // processStimulus to rotate the cube
    public void processStimulus(Enumeration criteria) {
    
      
      targetRope.getTransform(targetRope3D);
		Vector3d Y=new Vector3d();
		targetRope3D.get(Y);
		x=Y.x;
		y=Y.y;
		z=Y.z;
		Vector3d scale=new Vector3d();
		targetRope3D.getScale(scale);
		yScale=scale.y;
		if(yScale<4.7)
		{targetRope3D.setTranslation(new Vector3f((float)(x),(float)(y-0.01),(float)(z)));
		targetRope3D.setScale(new Vector3d(1.0,(double)((yScale*0.2+0.02)/0.2),1.0));
		targetRope.setTransform(targetRope3D);
		
		
		targetHook3D.setTranslation(new Vector3f((float)(x),(float)(y-0.10-yScale*0.1),(float)(z)));
		targetHook.setTransform(targetHook3D);
      
      	if(loadAndUnloadBehavior.bLoad)	
			
        {targetAssembleBox.getTransform(targetAssembleBox3D);
		Vector3d Y1=new Vector3d();
		targetAssembleBox3D.get(Y1);
		x1=Y1.x;
		y1=Y1.y;
		z1=Y1.z;
		
        targetAssembleBox3D.setTranslation(new Vector3f((float)(x1),(float)(y1-0.01),(float)(z1)));
         
         targetAssembleBox.setTransform(targetAssembleBox3D);}}
         

	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}

//控制吊钩向上运动
class hookMoveUpBehavior extends Behavior
implements ActionListener {

    private TransformGroup targetRope;
    private Transform3D targetRope3D = new Transform3D();
    private TransformGroup targetHook;
    private Transform3D targetHook3D = new Transform3D();
    private TransformGroup targetAssembleBox;
    private Transform3D targetAssembleBox3D=new Transform3D();
    private double yScale=1.0;
	    private double x=0.0;
	    private double y=0.0;
	    private double z=0.0;
	    private double x1=0.0;
	    private double y1=0.0;
	    private double z1=0.0;
	    private double x2=0.0;
	    private double y2=0.0;
	    private double z2=0.0;
    private WakeupCriterion criterion;
    
    // create a new AWTInteractionBehavior
    public  hookMoveUpBehavior(TransformGroup hook,TransformGroup rope,TransformGroup assembleBox) {
	this.targetHook = hook;
	this.targetRope=rope;
	  this.targetAssembleBox=assembleBox;  }

    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this,
 					     MouseEvent.MOUSE_CLICKED);
	wakeupOn(criterion);
    }

    // processStimulus to rotate the cube
    public void processStimulus(Enumeration criteria) {
      targetAssembleBox.getTransform(targetAssembleBox3D);
        Vector3d Y1=new Vector3d();
		targetAssembleBox3D.get(Y1);
		x1=Y1.x;
		y1=Y1.y;
		z1=Y1.z;
      
      targetRope.getTransform(targetRope3D);
		Vector3d Y=new Vector3d();
		targetRope3D.get(Y);
		x=Y.x;
		y=Y.y;
		z=Y.z;
		Vector3d scale=new Vector3d();
		targetRope3D.getScale(scale);
		yScale=scale.y;
	 if(yScale>=1.0)
		{targetRope3D.setTranslation(new Vector3f((float)(x),(float)(y+0.01),(float)(z)));
		targetRope3D.setScale(new Vector3d(1.0,(double)((yScale*0.2-0.02)/0.2),1.0));
		targetRope.setTransform(targetRope3D);
		
		
		targetHook3D.setTranslation(new Vector3f((float)(x),(float)(y-0.06-yScale*0.1),(float)(z)));
		targetHook.setTransform(targetHook3D);
      
      	if((loadAndUnloadBehavior.bLoad)&&((y-0.06-yScale*0.1-y1)<0.01))	
			
        {
		
        	targetAssembleBox3D.setTranslation(new Vector3f((float)(x1),(float)(y1+0.01),(float)(z1)));
         
         targetAssembleBox.setTransform(targetAssembleBox3D);}}
         

	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}

//控制吊钩的旋转
class hookRotateBehavior extends Behavior
implements ActionListener {

    private TransformGroup targetHook;
    private Transform3D targetHook3D = new Transform3D();
    private TransformGroup targetRope;
    private Transform3D targetRope3D = new Transform3D();
    private double angle=0.0;
	 private double y=0.0;
	 private double x=0.0; 
	 private double z=0.0;
	 private double y1=0.0;
	 private double x1=0.0; 
	 private double z1=0.0;
    private WakeupCriterion criterion;
    private TransformGroup targetAssembleBox;
    private Transform3D targetAssembleBox3D=new Transform3D();
    // create a new AWTInteractionBehavior
    public  hookRotateBehavior(TransformGroup rope,TransformGroup hook,TransformGroup assembleBox) {
	this.targetHook = hook;
	this.targetRope = rope;
	this.targetAssembleBox=assembleBox;
	    }

    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this,
 					     MouseEvent.MOUSE_CLICKED);
	wakeupOn(criterion);
    }

    // processStimulus to rotate the cube
    public void processStimulus(Enumeration criteria) {
    
      targetHook.getTransform(targetHook3D);
		Vector3d X=new Vector3d();
		targetHook3D.get(X);
		x=X.x;
		y=X.y;
		z=X.z;
      	Vector3d scale=new Vector3d();
		
		
		angle += Math.toRadians(30.0);
		
		
		targetHook3D.rotY(angle);
	targetHook3D.setTranslation(new Vector3f((float)(x),(float)(y),(float)(z)));
	
	targetHook.setTransform(targetHook3D);
      	if(loadAndUnloadBehavior.bLoad)	
		{targetAssembleBox.getTransform(targetAssembleBox3D);
		Vector3d Y1=new Vector3d();
		targetAssembleBox3D.get(Y1);
		x1=Y1.x;
		y1=Y1.y;
		z1=Y1.z;
			targetAssembleBox3D.rotY(angle);	
        targetAssembleBox3D.setTranslation(new Vector3f((float)(x1),(float)(y1),(float)(z1)));
         
         targetAssembleBox.setTransform(targetAssembleBox3D); } 

	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}

//控制横梁向左移动
class beamTranslateLeftBehavior extends Behavior
implements ActionListener {
private TransformGroup targetAssembleBox;
    private Transform3D targetAssembleBox3D=new Transform3D();
    private TransformGroup targetBeam;
    private Transform3D targetBeam3D = new Transform3D();
    private TransformGroup targetHook;
    private Transform3D targetHook3D = new Transform3D();    
    private double x=0.0;
    private double x1=0.0;
    private double y=0.0;
    private double y1=0.0;
    private double z=0.0;
    private double z1=0.0;
    private double x2=0.0;
    private double y2=0.0;
    private double z2=0.0;
    private WakeupCriterion criterion;
    
    // create a new AWTInteractionBehavior
    public  beamTranslateLeftBehavior(TransformGroup beam,TransformGroup assembleBox,TransformGroup hook) {
	this.targetBeam = beam;
	this.targetAssembleBox=assembleBox;	    
    this.targetHook=hook;}
    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this,
 					     MouseEvent.MOUSE_CLICKED);
	wakeupOn(criterion);
    }

    // processStimulus to rotate the cube
    public void processStimulus(Enumeration criteria) {
    
     
      targetBeam.getTransform(targetBeam3D);
		Vector3d X=new Vector3d();
		targetBeam3D.get(X);
		x=X.x;
		y=X.y;
      	z=X.z;
		//targetHook.getTransform(targetHook3D);
		//Vector3d X1=new Vector3d();
		//targetHook3D.get(X1);
		//x1=X1.x;
		//y1=X1.y;
      	//z1=X1.z;
      	if(x>=-1.1)
		{targetBeam3D.setTranslation(new Vector3f((float)(x-0.05),(float)(y),(float)(z)));
		//targetRope3D.setScale(new Vector3d(1.0,(double)(yScale),1.0));
		targetBeam.setTransform(targetBeam3D);
		
		if(loadAndUnloadBehavior.bLoad)		
			
        {targetAssembleBox.getTransform(targetAssembleBox3D);
		Vector3d Y1=new Vector3d();
		targetAssembleBox3D.get(Y1);
		x2=Y1.x;
		y2=Y1.y;
		z2=Y1.z;
        	targetAssembleBox3D.setTranslation(new Vector3f((float)(x2-0.03),(float)(y2),(float)(z2)));
         
         targetAssembleBox.setTransform(targetAssembleBox3D);}}
		
	

	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}
//控制横梁向右移动
class beamTranslateRightBehavior extends Behavior
implements ActionListener {

    private TransformGroup targetBeam;
    private Transform3D targetBeam3D = new Transform3D();
    private TransformGroup targetAssembleBox;
    private Transform3D targetAssembleBox3D=new Transform3D();
    private TransformGroup targetHook;
    private Transform3D targetHook3D = new Transform3D();  
    private double x=0.0;
    private double x1=0.0;
    private double y=0.0;
    private double y1=0.0;
    private double z=0.0;
    private double z1=0.0;
    private double x2=0.0;
    private double y2=0.0;
    private double z2=0.0;
    private WakeupCriterion criterion;
    
    // create a new AWTInteractionBehavior
    public  beamTranslateRightBehavior(TransformGroup beam,TransformGroup assembleBox,TransformGroup hook) {
	this.targetBeam = beam;
	this.targetAssembleBox=assembleBox;	   
    this.targetHook=hook; }
    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this,
 					     MouseEvent.MOUSE_CLICKED);
	wakeupOn(criterion);
    }

    
    public void processStimulus(Enumeration criteria) {
    
     
      targetBeam.getTransform(targetBeam3D);
		Vector3d X=new Vector3d();
		targetBeam3D.get(X);
		x=X.x;
		y=X.y;
      	z=X.z;
		
		//targetHook.getTransform(targetHook3D);
		//Vector3d X1=new Vector3d();
		//targetHook3D.get(X1);
		//x1=X1.x;
		//y1=X1.y;
      	//z1=X1.z;
      	if(x<=1.1)
		{targetBeam3D.setTranslation(new Vector3f((float)(x+0.05),(float)(y),(float)(z)));
		//targetRope3D.setScale(new Vector3d(1.0,(double)(yScale),1.0));
		targetBeam.setTransform(targetBeam3D);
		if(loadAndUnloadBehavior.bLoad)
		
        {targetAssembleBox.getTransform(targetAssembleBox3D);
		Vector3d Y1=new Vector3d();
		targetAssembleBox3D.get(Y1);
		x2=Y1.x;
		y2=Y1.y;
		z2=Y1.z;
        	targetAssembleBox3D.setTranslation(new Vector3f((float)(x2+0.03),(float)(y2),(float)(z2)));
         
         targetAssembleBox.setTransform(targetAssembleBox3D);}}
		   

	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}

//控制吊钩向后移动
class hookTranslateBackBehavior extends Behavior
implements ActionListener {

    private TransformGroup targetHook;
    private Transform3D targetHook3D = new Transform3D();
    private TransformGroup targetRope;
    private Transform3D targetRope3D = new Transform3D();
    //private double factor;   
    private double x=0.0;
    private double y=0.0;
    private double z=0.0;
    private double x1=0.0;
    private double y1=0.0;
    private double z1=0.0;
    private double yScale=1.0;
    private TransformGroup targetAssembleBox;
    private Transform3D targetAssembleBox3D=new Transform3D();
    private WakeupCriterion criterion;
    
    // create a new AWTInteractionBehavior
    public  hookTranslateBackBehavior(TransformGroup rope,TransformGroup hook,TransformGroup assembleBox) {
	this.targetRope = rope;
	this.targetHook = hook;
		    
this.targetAssembleBox=assembleBox;}
    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this,
 					     MouseEvent.MOUSE_CLICKED);
	wakeupOn(criterion);
    }

    // processStimulus to rotate the cube
    public void processStimulus(Enumeration criteria) {
    
     targetRope.getTransform(targetRope3D);
		Vector3d X=new Vector3d();
		targetRope3D.get(X);
		x=X.x;
		y=X.y;
		z=X.z;
      	Vector3d scale=new Vector3d();
		targetRope3D.getScale(scale);
		yScale=scale.y;
		
		if(z>=-0.8)
		{targetRope3D.setTranslation(new Vector3f((float)(x),(float)(y),(float)(z-0.05)));
		//targetRope3D.setScale(new Vector3d(1.0,(double)(yScale),1.0));
		targetRope.setTransform(targetRope3D);
		
		
		
	targetHook3D.setTranslation(new Vector3f((float)(x),(float)(y-0.08-yScale*0.1),(float)(z-0.05)));
targetHook.setTransform(targetHook3D);
     
     	if(loadAndUnloadBehavior.bLoad)	
			
        {targetAssembleBox.getTransform(targetAssembleBox3D);
		Vector3d Y1=new Vector3d();
		targetAssembleBox3D.get(Y1);
		x1=Y1.x;
		y1=Y1.y;
		z1=Y1.z;
        	targetAssembleBox3D.setTranslation(new Vector3f((float)(x1),(float)(y1),(float)(z1-0.05)));
         
         targetAssembleBox.setTransform(targetAssembleBox3D);}}
     
      

	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}
//控制吊钩向前移动
class hookTranslateForwardBehavior extends Behavior
implements ActionListener {
private TransformGroup targetAssembleBox;
    private Transform3D targetAssembleBox3D=new Transform3D();
    private TransformGroup targetHook;
    private Transform3D targetHook3D = new Transform3D();
    private TransformGroup targetRope;
    private Transform3D targetRope3D = new Transform3D();
    //private double factor;   
    private double x=0.0;
    private double y=0.0;
    private double z=0.0;
    private double x1=0.0;
    private double y1=0.0;
    private double z1=0.0;
    private double yScale=1.0;
    private WakeupCriterion criterion;
    
    // create a new AWTInteractionBehavior
    public  hookTranslateForwardBehavior(TransformGroup rope,TransformGroup hook,TransformGroup assembleBox) {
	this.targetRope = rope;
	this.targetHook = hook;
	this.targetAssembleBox=assembleBox;	    }

    // initialize the behavior to wakeup on a behavior post with the id
    // MouseEvent.MOUSE_CLICKED
    public void initialize() {
	criterion = new WakeupOnBehaviorPost(this,
 					     MouseEvent.MOUSE_CLICKED);
	wakeupOn(criterion);
    }

    // processStimulus to rotate the cube
    public void processStimulus(Enumeration criteria) {
    
     
      targetRope.getTransform(targetRope3D);
		Vector3d X=new Vector3d();
		targetRope3D.get(X);
		x=X.x;
		y=X.y;
		z=X.z;
      	Vector3d scale=new Vector3d();
		targetRope3D.getScale(scale);
		yScale=scale.y;
		
		if(z<=0.5)
		{targetRope3D.setTranslation(new Vector3f((float)(x),(float)(y),(float)(z+0.05)));
		//targetRope3D.setScale(new Vector3d(1.0,(double)(yScale),1.0));
		targetRope.setTransform(targetRope3D);
					
	targetHook3D.setTranslation(new Vector3f((float)(x+0.01),(float)(y-0.08-yScale*0.1),(float)(z+0.05)));
targetHook.setTransform(targetHook3D);
      
		if(loadAndUnloadBehavior.bLoad)	
			
        {targetAssembleBox.getTransform(targetAssembleBox3D);
		Vector3d Y1=new Vector3d();
		targetAssembleBox3D.get(Y1);
		x1=Y1.x;
		y1=Y1.y;
		z1=Y1.z;
        	targetAssembleBox3D.setTranslation(new Vector3f((float)(x1),(float)(y1),(float)(z1+0.05)));
         
         targetAssembleBox.setTransform(targetAssembleBox3D);}}	
		   

	wakeupOn(criterion);
    }

    // when the mouse is clicked, postId for the behavior
    public void actionPerformed(ActionEvent e) {
	postId(MouseEvent.MOUSE_CLICKED);
    }
}

public class MyCraneFinal1 extends Applet{

private java.net.URL backgroundImage=null;
private java.net.URL craneImage=null;
private java.net.URL assembleBoxImage=null;
private java.net.URL driverRoomImage=null;
private java.net.URL hookImage=null;
private java.net.URL floorImage=null;



Button hookMoveUp=new Button("吊钩上移");
Button hookMoveDown=new Button("吊钩下移");
Button hookTranslateBack=new Button("吊钩后移");
Button hookTranslateForward=new Button("吊钩前移");
Button hookRotate=new Button("吊钩旋转");
Button beamTranslateLeft=new Button("横梁左移");
Button beamTranslateRight=new Button("横梁右移");
Button loadAndUnload=new Button("起吊(卸载)集装箱");
Label	 label=new Label("虚拟起重机控制平台");
//创造场景图（开始）
public BranchGroup createSceneGraph()
{BranchGroup objRoot=new BranchGroup();
MouseTranslate myMT=null;
BoundingSphere bounds=new BoundingSphere(new Point3d(0.0,0.0,0.0),200.0);



//设置背景
//Color3f bgColor=new Color3f(1.0f,1.0f,1.0f);
Background bg=new Background();
TextureLoader loaderBg=new TextureLoader(backgroundImage,this);
ImageComponent2D imageBg=loaderBg.getImage();
bg.setImage(imageBg);


bg.setApplicationBounds(bounds);
objRoot.addChild(bg);
TransformGroup objTrans=new TransformGroup();
objRoot.addChild(objTrans);

//设置总体坐标系（开始）
Transform3D transform=new Transform3D();
transform.setTranslation(new Vector3f(0.0f,-0.14f,-1.8f));
TransformGroup trans=new TransformGroup(transform);
objTrans.addChild(trans);
 
 
 
 //设置起重机文理外观（app1)
TextureLoader myLoader1=new TextureLoader(craneImage,this);
ImageComponent2D myImage1=myLoader1.getImage();
if(myImage1==null)
{System.err.println("Cannot load texture");
return null;}
Texture2D myTex1=(Texture2D)myLoader1.getTexture();
Appearance app1=new Appearance();
app1.setTexture(myTex1);
Material mat1=new Material();
app1.setMaterial(mat1);


//起重机四根柱子的模子（开始）
float[] vert1={-0.035f,.035f,.09f,  
              -0.035f,0.035f,-0.09f,
              0.035f,0.035f,-0.09f,
              0.035f,0.035f,0.09f,};
QuadArray plane1=new QuadArray(4,GeometryArray.COORDINATES|GeometryArray.TEXTURE_COORDINATE_2);
plane1.setCoordinates(0,vert1);
Point2f q1=new Point2f();
q1.set(0.0f,1.0f);
plane1.setTextureCoordinate(0,q1);
q1.set(0.0f,0.0f);
plane1.setTextureCoordinate(1,q1);
q1.set(1.0f,0.0f);
plane1.setTextureCoordinate(2,q1);
q1.set(1.0f,1.0f);
plane1.setTextureCoordinate(3,q1); 
Shape3D shape1=new Shape3D();
shape1.setGeometry(plane1);
shape1.setAppearance(app1);
           
              
float[] vert2={-0.035f,.035f,.09f,  
               -0.09f,1.25f,0.09f,
               -0.09f,1.25f,-0.09f,
              -0.035f,0.035f,-0.09f,
              };
QuadArray plane2=new QuadArray(4,GeometryArray.COORDINATES|GeometryArray.TEXTURE_COORDINATE_2);
plane2.setCoordinates(0,vert2);           
Point2f q2=new Point2f();
q2.set(0.0f,1.0f);
plane2.setTextureCoordinate(0,q2);
q2.set(0.0f,0.0f);
plane2.setTextureCoordinate(1,q2);
q2.set(1.0f,0.0f);
plane2.setTextureCoordinate(2,q2);
q2.set(1.0f,1.0f);
plane2.setTextureCoordinate(3,q2);
Shape3D shape2=new Shape3D();
shape2.setGeometry(plane2);
shape2.setAppearance(app1);

float[] vert3={ -0.035f,0.035f,-0.09f,
              -0.09f,1.25f,-0.09f,
              0.09f,1.25f,-0.09f,
              0.035f,0.035f,-0.09f,
              };
 QuadArray plane3=new QuadArray(4,GeometryArray.COORDINATES|GeometryArray.TEXTURE_COORDINATE_2);
plane3.setCoordinates(0,vert3);             
              
 Point2f q3=new Point2f();
q3.set(0.0f,1.0f);
plane3.setTextureCoordinate(0,q3);
q3.set(0.0f,0.0f);
plane3.setTextureCoordinate(1,q3);
q3.set(1.0f,0.0f);
plane3.setTextureCoordinate(2,q3);
q3.set(1.0f,1.0f);
plane3.setTextureCoordinate(3,q3);
Shape3D shape3=new Shape3D();
shape3.setGeometry(plane3);
shape3.setAppearance(app1);            
float[] vert4={0.035f,0.035f,-0.09f,
              0.09f,1.25f,-0.09f,
              0.09f,1.25f,0.09f,
              0.035f,0.035f,0.09f,
              };           
QuadArray plane4=new QuadArray(4,GeometryArray.COORDINATES|GeometryArray.TEXTURE_COORDINATE_2);
plane4.setCoordinates(0,vert4);               
              
   Point2f q4=new Point2f();
q4.set(0.0f,1.0f);
plane4.setTextureCoordinate(0,q4);
q4.set(0.0f,0.0f);
plane4.setTextureCoordinate(1,q4);
q4.set(1.0f,0.0f);
plane4.setTextureCoordinate(2,q4);
q4.set(1.0f,1.0f);
plane4.setTextureCoordinate(3,q4);
Shape3D shape4=new Shape3D();
shape4.setGeometry(plane4);
shape4.setAppearance(app1);           
              
              
float[] vert5={0.035f,0.035f,0.09f,
	           0.09f,1.25f,0.09f,
             -0.09f,1.25f,0.09f,
		     -0.035f,.035f,.09f, } ;
QuadArray plane5=new QuadArray(4,GeometryArray.COORDINATES|GeometryArray.TEXTURE_COORDINATE_2);
plane5.setCoordinates(0,vert5);                
  Point2f q5=new Point2f();
q5.set(0.0f,1.0f);
plane5.setTextureCoordinate(0,q5);
q5.set(0.0f,0.0f);
plane5.setTextureCoordinate(1,q5);
q5.set(1.0f,0.0f);
plane5.setTextureCoordinate(2,q5);
q5.set(1.0f,1.0f);
plane5.setTextureCoordinate(3,q5); 
Shape3D shape5=new Shape3D();
shape5.setGeometry(plane5);
shape5.setAppearance(app1);           
float[] vert6={-0.09f,1.25f,0.09f,
              -0.09f,1.25f,-0.09f,
              0.09f,1.25f,-0.09f,
              0.09f,1.25f,0.09f,};      
QuadArray plane6=new QuadArray(4,GeometryArray.COORDINATES|GeometryArray.TEXTURE_COORDINATE_2);
plane6.setCoordinates(0,vert6);                        

Point2f q6=new Point2f();
q6.set(0.0f,1.0f);
plane6.setTextureCoordinate(0,q6);
q6.set(0.0f,0.0f);
plane6.setTextureCoordinate(1,q6);
q6.set(1.0f,0.0f);
plane6.setTextureCoordinate(2,q6);
q6.set(1.0f,1.0f);
plane6.setTextureCoordinate(3,q6);
Shape3D shape6=new Shape3D();
shape6.setGeometry(plane6);
shape6.setAppearance(app1);

Group group=new Group();
group.addChild(shape1);
group.addChild(shape2);
group.addChild(shape3);
group.addChild(shape4);
group.addChild(shape5);
group.addChild(shape6);
SharedGroup shared=new SharedGroup();
shared.addChild(group);
//起重机四根柱子的模子（结束）






//最高处的栏杆的模子（开始）
Cylinder cylinder=new Cylinder(0.01f,0.35f,Cylinder.GENERATE_NORMALS|Cylinder.GENERATE_TEXTURE_COORDS,app1);
SharedGroup shared1=new SharedGroup();
shared1.addChild(cylinder);
Transform3D[] ti1;
TransformGroup[] gi1;
ti1=new Transform3D[7];
gi1=new TransformGroup[7];
float x=-2.7f,y=-0.185f;
Group group1=new Group();
Box box=new Box(2.7f,0.008f,0.005f,Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS, app1);
for(int i=0;i<7;i++)
{ti1[i]=new Transform3D();
ti1[i].setTranslation(new Vector3f(x,y,0.0f));
gi1[i]=new TransformGroup(ti1[i]);
gi1[i].addChild(new Link(shared1));
x+=0.9f;
group1.addChild(gi1[i]);}
group1.addChild(box);
SharedGroup shared2=new SharedGroup();
shared2.addChild(group1);
Group group2=new Group();
Box boxi=new Box(0.005f,0.008f,0.815f,Box.GENERATE_NORMALS|Box.GENERATE_TEXTURE_COORDS, app1);
group2.addChild(boxi);
SharedGroup shared4=new SharedGroup();
shared4.addChild(group2);
//最高处的栏杆的模子（结束）


//设置集装箱文理外观(app3)
TextureLoader myLoader3=new TextureLoader(assembleBoxImage,this);
ImageComponent2D myImage3=myLoader3.getImage();
if(myImage3==null)
{System.err.println("Cannot load texture");
return null;}
Texture2D myTex3=(Texture2D)myLoader3.getTexture();
TextureAttributes textAttr=new TextureAttributes();
Transform3D myTrans=new Transform3D();

myTrans.setScale(new Vector3d(0.0,2.0,0.0));
//myTrans.rotZ(Math.PI/2.0);
textAttr.setTextureTransform(myTrans);

Appearance app3=new Appearance();
app3.setTextureAttributes(textAttr);
app3.setTexture(myTex3);
Material mat3=new Material();
app3.setMaterial(mat3);

//司机室的模子
TextureLoader myLoader5=new TextureLoader(driverRoomImage,this);
ImageComponent2D myImage5=myLoader5.getImage();
if(myImage5==null)
{System.err.println("Cannot load texture");
return null;}
Texture2D myTex5=(Texture2D)myLoader5.getTexture();
Appearance app5=new Appearance();
app5.setTexture(myTex5);
Material mat5=new Material();
app5.setMaterial(mat5);
Box box7=new Box(0.20f,0.25f,0.2f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app5);
SharedGroup shared3=new SharedGroup();
shared3.addChild(box7);

  
 //起重机的两个底座（开始）
Transform3D t=new Transform3D();
t.setTranslation(new Vector3f(-1.3f,-0.30f,-2.5f));
TransformGroup g1=new TransformGroup(t);
Box box1=new Box(0.06f,.07f,1.5f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);

//其中一个底座上的两根柱子
Transform3D t1=new Transform3D();
t1.setTranslation(new Vector3f(0.0f,0.025f,-0.70f));
TransformGroup g11=new TransformGroup(t1);
g11.addChild(new Link(shared));
Transform3D t2=new Transform3D();
t2.setTranslation(new Vector3f(0.0f,0.025f,0.70f));
TransformGroup g12=new TransformGroup(t2);
g12.addChild(new Link(shared));
g1.addChild(g11);
g1.addChild(g12);
g1.addChild(box1);

//另外一个底座的两根柱子 
t=new Transform3D();
t.setTranslation(new Vector3f(1.3f,-0.30f,-2.5f));
   
TransformGroup g2=new TransformGroup(t);
Box box2=new Box(0.06f,0.07f,1.5f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);

Transform3D t3=new Transform3D();
t3.setTranslation(new Vector3f(0.0f,0.025f,-0.70f));

TransformGroup g21=new TransformGroup(t3);
g21.addChild(new Link(shared));

Transform3D t4=new Transform3D();
t4.setTranslation(new Vector3f(0.0f,0.025f,0.70f));

TransformGroup g22=new TransformGroup(t4);

g22.addChild(new Link(shared));
g2.addChild(g21);
g2.addChild(g22);
g2.addChild(box2);
//起重机的两个底座（结束）




//起重机的前面的大梁
Transform3D t5=new Transform3D();
t5.setTranslation(new Vector3f(0.0f,1.18f,-2.5f));
TransformGroup g3=new TransformGroup(t5);
Box box3=new Box(2.7f,0.10f,0.005f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);



//起重机最高处前面的栏杆
Transform3D t52=new Transform3D();
t52.setTranslation(new Vector3f(0.0f,0.45f,0.0f));
TransformGroup g32=new TransformGroup(t52);
g32.addChild(new Link(shared2));


//起重机挂钩的横梁
Transform3D tr=new Transform3D();
tr.setTranslation(new Vector3f(0.0f,0.0f,-0.8f));
TransformGroup gr=new TransformGroup(tr);

//横梁在水平移动
gr.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
gr.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
myMT=new MouseTranslate();
myMT.setTransformGroup(gr);
myMT.setSchedulingBounds(new BoundingBox(new Point3d(-1.35,0.0,-4.5),new Point3d(1.35,1.0,2.5)));
myMT.setFactor(0.005,0.0);
gr.addChild(myMT);
Box box9=new Box(0.25f,0.010f,0.8f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);


TextureLoader myLoader6=new TextureLoader(hookImage,this);
ImageComponent2D myImage6=myLoader6.getImage();
if(myImage6==null)
{System.err.println("Cannot load texture");
return null;}
Texture2D myTex6=(Texture2D)myLoader6.getTexture();
Appearance app6=new Appearance();
app6.setTexture(myTex6);
Material mat6=new Material();
app6.setMaterial(mat6);


//起重机的挂钩
Transform3D th=new Transform3D();
th.setTranslation(new Vector3f(0.0f,-0.1f,0.0f));
TransformGroup gh=new TransformGroup(th);
gh.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
gh.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Cylinder ch=new Cylinder(0.02f,0.2f,Cylinder.GENERATE_NORMALS|Cylinder.GENERATE_TEXTURE_COORDS,app6);
gh.addChild(ch);
Transform3D tc=new Transform3D();
tc.setTranslation(new Vector3f(0.0f,-0.28f,0.0f));
TransformGroup gc=new TransformGroup(tc);
gc.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
gc.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Cylinder[] ci;
Transform3D[] ti;
TransformGroup[] gi;
ci=new Cylinder[245];
ti=new Transform3D[245];
gi=new TransformGroup[245];
double j=Math.PI*90/180;
for(int i=0;i<245;i++)
{ti[i]=new Transform3D();
ti[i].setTranslation(new Vector3f((float)(0.08*Math.cos(j)),(float)(0.08*Math.sin(j)),0.0f));
 
gi[i]=new TransformGroup(ti[i]);
ci[i]=new Cylinder(0.02f,(float)(0.080*(Math.PI*1/180)),Cylinder.GENERATE_NORMALS|Cylinder.GENERATE_TEXTURE_COORDS,app6);
gi[i].addChild(ci[i]);
gc.addChild(gi[i]);
j+=Math.PI*1/180;}



//集装箱
Transform3D ta=new Transform3D();
ta.rotY(Math.PI/5);
ta.setTranslation(new Vector3f(0.0f,-0.05f,0.0f));

TransformGroup ga=new TransformGroup(ta);
ga.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
ga.setCapability(TransformGroup.ALLOW_TRANSFORM_READ);
Box box8=new Box(0.25f,0.15f,0.25f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app3);


//集装箱上的吊绳
float[] vert8={-0.12f,0.0f,0.0f,
              0.12f,0.0f,0.0f,
              0.12f,0.2f,0.f,
              -0.12f,0.2f,0.f,};      
QuadArray plane8=new QuadArray(4,GeometryArray.COORDINATES);
plane8.setCoordinates(0,vert8);                        
PolygonAttributes pa=new PolygonAttributes();
//LineAttributes linea=new LineAttributes();
//linea.setLineWidth(2.0f);

pa.setPolygonMode(1);

Appearance app4=new Appearance();
app4.setPolygonAttributes(pa);
app4.setTexture(myTex6);
Shape3D shape8=new Shape3D();
shape8.setAppearance(app4);
shape8.setGeometry(plane8);
ga.addChild(shape8);
ga.addChild(box8);
g3.addChild(g32);
trans.addChild(ga);
g3.addChild(box3);


gr.addChild(gh);
gr.addChild(box9);
gr.addChild(gc);
g3.addChild(gr);



//起重机后面的大梁
Transform3D t6=new Transform3D();
t6.setTranslation(new Vector3f(0.0f,1.18f,-4.15f));
TransformGroup g4=new TransformGroup(t6);
Box box4=new Box(2.7f,0.10f,0.005f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);

//起重机后面的司机室
Transform3D t61=new Transform3D();
t61.setTranslation(new Vector3f(1.15f,-0.36f,0.0f));
TransformGroup g41=new TransformGroup(t61);
g41.addChild(new Link(shared3));
Transform3D t611=new Transform3D();
t611.setTranslation(new Vector3f(0.0f,-0.25f,0.0f));
TransformGroup g411=new TransformGroup(t611);
Box box10=new Box(0.20f,0.005f,0.3f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);
g411.addChild(box10);
g41.addChild(g411);


//起重机后面最高处的栏杆
Transform3D t62=new Transform3D();
t62.setTranslation(new Vector3f(0.0f,0.45f,0.0f));
TransformGroup g42=new TransformGroup(t62);
g42.addChild(new Link(shared2));
g4.addChild(g41);
g4.addChild(g42);
g4.addChild(box4);


//起重机左边的横梁
Transform3D t7=new Transform3D();
t7.setTranslation(new Vector3f(-2.7f,1.18f,-3.3f));
TransformGroup g5=new TransformGroup(t7);
Box box5=new Box(0.015f,0.10f,0.8f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);


//起重机最高处左边的栏杆
Transform3D t71=new Transform3D();
t71.setTranslation(new Vector3f(0.0f,0.45f,0.0f));
TransformGroup g51=new TransformGroup(t71);
g51.addChild(new Link(shared4));

Transform3D t72=new Transform3D();
t72.setTranslation(new Vector3f(0.0f,0.26f,0.0f));
TransformGroup g52=new TransformGroup(t72);
g52.addChild(new Link(shared1));
g5.addChild(g52);
g5.addChild(g51);
g5.addChild(box5);


//起重机右边的横梁
Transform3D t8=new Transform3D();
t8.setTranslation(new Vector3f(2.7f,1.18f,-3.3f));
TransformGroup g6=new TransformGroup(t8);
Box box6=new Box(0.015f,0.10f,0.8f,Box.GENERATE_TEXTURE_COORDS|Box.GENERATE_NORMALS,app1);


//起重机最高处右边的栏杆
Transform3D t81=new Transform3D();
t81.setTranslation(new Vector3f(0.0f,0.45f,0.0f));
TransformGroup g61=new TransformGroup(t81);
g61.addChild(new Link(shared4));
Transform3D t82=new Transform3D();
t82.setTranslation(new Vector3f(0.0f,0.26f,0.0f));
TransformGroup g62=new TransformGroup(t82);
g62.addChild(new Link(shared1));
g6.addChild(g62);
g6.addChild(g61);
g6.addChild(box6);




trans.addChild(g1);
trans.addChild(g2);
trans.addChild(g3);
trans.addChild(g4);
trans.addChild(g5);
trans.addChild(g6);
//设置总体坐标系（结束）

//设置地面文理属性
Shape3D shape=new Shape3D();
TextureLoader myLoader=new TextureLoader(floorImage,this);
ImageComponent2D myImage=myLoader.getImage();
if(myImage==null)
{System.err.println("Cannot load texture");
return null;}
Texture2D myTex=(Texture2D)myLoader.getTexture();
myTex.setBoundaryModeS(Texture.WRAP);
Appearance app=new Appearance();
app.setTexture(myTex);
Material mat=new Material();
app.setMaterial(mat);
TextureAttributes myTexAttr=new TextureAttributes();
Transform3D myTrans1=new Transform3D();
myTrans1.setScale(new Vector3d(4.0,4.0,0.0));
myTexAttr.setTextureTransform(myTrans1);
myTexAttr.setTextureMode(TextureAttributes.MODULATE);
app.setTextureAttributes(myTexAttr);




//地面指定文理坐标
QuadArray plane=new QuadArray(4,QuadArray.COORDINATES|QuadArray.TEXTURE_COORDINATE_2);
Point3f p=new Point3f();
p.set(-8.f,-0.1f,-10.0f);
plane.setCoordinate(0,p);
p.set(-8.0f,-1.0f,0.0f);
plane.setCoordinate(1,p);
p.set(8.0f,-1.0f,0.0f);
plane.setCoordinate(2,p);
p.set(8.0f,-0.1f,-10.0f);
plane.setCoordinate(3,p);


Point2f q=new Point2f();
q.set(0.0f,1.0f);
plane.setTextureCoordinate(0,q);
q.set(0.0f,0.0f);
plane.setTextureCoordinate(1,q);
q.set(1.0f,0.0f);
plane.setTextureCoordinate(2,q);
q.set(1.0f,1.0f);
plane.setTextureCoordinate(3,q);





shape.setGeometry(plane);
shape.setAppearance(app);

objRoot.addChild(shape);

hookMoveDownBehavior awtHookMoveDownBehavior =
	    new hookMoveDownBehavior(gc,gh,ga);
	hookMoveDown.addActionListener(awtHookMoveDownBehavior);
	awtHookMoveDownBehavior.setSchedulingBounds(bounds);
gr.addChild(awtHookMoveDownBehavior);

hookMoveUpBehavior awtHookMoveUpBehavior =
	    new hookMoveUpBehavior(gc,gh,ga);
	hookMoveUp.addActionListener(awtHookMoveUpBehavior);
	awtHookMoveUpBehavior.setSchedulingBounds(bounds);
gr.addChild(awtHookMoveUpBehavior);

hookRotateBehavior awtHookRotateBehavior =
	    new hookRotateBehavior(gh,gc,ga);
	hookRotate.addActionListener(awtHookRotateBehavior);
	awtHookRotateBehavior.setSchedulingBounds(bounds);
gr.addChild(awtHookRotateBehavior);

beamTranslateLeftBehavior awtBeamTranslateLeftBehavior =
	    new beamTranslateLeftBehavior(gr,ga,gc);
	beamTranslateLeft.addActionListener(awtBeamTranslateLeftBehavior);
	awtBeamTranslateLeftBehavior.setSchedulingBounds(bounds);
gr.addChild(awtBeamTranslateLeftBehavior);
  
 beamTranslateRightBehavior awtBeamTranslateRightBehavior =
	    new beamTranslateRightBehavior(gr,ga,gc);
	beamTranslateRight.addActionListener(awtBeamTranslateRightBehavior);
	awtBeamTranslateRightBehavior.setSchedulingBounds(bounds);
gr.addChild(awtBeamTranslateRightBehavior); 

hookTranslateBackBehavior awtHookTranslateBackBehavior =
	    new hookTranslateBackBehavior(gh,gc,ga);
	hookTranslateBack.addActionListener(awtHookTranslateBackBehavior);
	awtHookTranslateBackBehavior.setSchedulingBounds(bounds);
gr.addChild(awtHookTranslateBackBehavior); 

hookTranslateForwardBehavior awtHookTranslateForwardBehavior =
	    new hookTranslateForwardBehavior(gh,gc,ga);
	hookTranslateForward.addActionListener(awtHookTranslateForwardBehavior);
	awtHookTranslateForwardBehavior.setSchedulingBounds(bounds);
gr.addChild(awtHookTranslateForwardBehavior);

loadAndUnloadBehavior awtLoadAndUnLoadBehavior =
	    new loadAndUnloadBehavior();
	loadAndUnload.addActionListener(awtLoadAndUnLoadBehavior);
	awtLoadAndUnLoadBehavior.setSchedulingBounds(bounds);
gr.addChild(awtLoadAndUnLoadBehavior);




//设置平行光
DirectionalLight lightD1=new DirectionalLight();
Vector3f direction=new Vector3f(-6.0f,-2.0f,-1.0f);
Color3f cyan=new Color3f(1.0f,1.0f,1.0f);
lightD1.setDirection(direction);
lightD1.setColor(cyan);
lightD1.setInfluencingBounds(bounds);
objRoot.addChild(lightD1);



//创建线性型雾效
LinearFog myLF=new LinearFog();
myLF.setColor(new Color3f(0.0f,0.0f,0.0f));
myLF.setFrontDistance(6.5);
myLF.setBackDistance(9.5);
myLF.setInfluencingBounds(bounds);
objRoot.addChild(myLF);

Clip myClip=new Clip();
myClip.setBackDistance(8.6);
myClip.setApplicationBounds(bounds);
objRoot.addChild(myClip);

objRoot.compile();
return objRoot;}
//创造场景图（结束）


//主类的构造函数1
public MyCraneFinal1(){}
//主类的构造函数2
public MyCraneFinal1(java.net.URL backgroundURL,java.net.URL craneURL,java.net.URL assembleBoxURL
,java.net.URL driverRoomURL,java.net.URL hookURL,java.net.URL floorURL)
{ backgroundImage=backgroundURL;
craneImage=craneURL;
assembleBoxImage=assembleBoxURL;
driverRoomImage=driverRoomURL;
hookImage=hookURL;
floorImage=floorURL;}
 public void init()
  {
  	if (backgroundImage == null) {
      // the path to the image for an applet
      try {
	backgroundImage = new java.net.URL(getCodeBase().toString() + 
				      "../java-programs/bg.jpg");
      }
     catch (java.net.MalformedURLException ex) {
	System.out.println(ex.getMessage());
	System.exit(1);
      }
    }

    if (craneImage == null) {
      // the path to the image for an applet
      try {
	craneImage = new java.net.URL(getCodeBase().toString() +
				    "../java-programs/crane0002.jpg");
      }
      catch (java.net.MalformedURLException ex) {
	System.out.println(ex.getMessage());
	System.exit(1);
      }
    }
  	if (assembleBoxImage == null) {
      // the path to the image for an applet
      try {
	assembleBoxImage = new java.net.URL(getCodeBase().toString() + 
				      "../java-programs/assemble box.jpg");
      }
      catch (java.net.MalformedURLException ex) {
	System.out.println(ex.getMessage());
	System.exit(1);
      }
    }
    if (driverRoomImage == null) {
      // the path to the image for an applet
      try {
	driverRoomImage = new java.net.URL(getCodeBase().toString() + 
				      "../java-programs/driver room.jpg");
      }
      catch (java.net.MalformedURLException ex) {
	System.out.println(ex.getMessage());
	System.exit(1);
      }
    }
    if (hookImage == null) {
      // the path to the image for an applet
      try {
	hookImage = new java.net.URL(getCodeBase().toString() + 
				      "../java-programs/hook1.jpg");
      }
      catch (java.net.MalformedURLException ex) {
	System.out.println(ex.getMessage());
	System.exit(1);
      }
    }
    if (floorImage == null) {
      // the path to the image for an applet
      try {
	floorImage = new java.net.URL(getCodeBase().toString() + 
				      "../java-programs/floor2.jpg");
      }
      catch (java.net.MalformedURLException ex) {
	System.out.println(ex.getMessage());
	System.exit(1);
      }
    }
  	
  	setLayout(new BorderLayout());
  GraphicsConfiguration config=SimpleUniverse.getPreferredConfiguration();


  Canvas3D c = new Canvas3D(config); 
  add("Center", c); 
  Panel p = new Panel();
  //p.setBackground(Color.blue);
  p.setForeground(Color.blue);
  p.setSize(p.getMaximumSize());
  //label.setBackground(Color.BLACK);
   label.setForeground(Color.red);
      
    p.add(label);
    p.add(beamTranslateLeft);
	p.add(beamTranslateRight);
	p.add(hookRotate);
	p.add(hookMoveUp);
	p.add(loadAndUnload);
	p.add(hookMoveDown);
	p.add(hookTranslateBack);
	p.add(hookTranslateForward);
	add("South", p);
  
   BranchGroup scene = createSceneGraph(); 
  if(scene==null)
    {System.err.println("cannot create the scene graph");
    return;}
SimpleUniverse u = new SimpleUniverse(c); 
u.getViewingPlatform().setNominalViewingTransform();
u.addBranchGraph(scene); 
} 
 
//显示文件的执行情况的框架函数 
 public static void main(String argv[])
  {
    java.net.URL backgroundURL = null;
    java.net.URL craneURL = null;
    java.net.URL assembleBoxURL = null;
    java.net.URL driverRoomURL = null;
    java.net.URL hookURL = null;
    java.net.URL floorURL = null;
    // the path to the image for an application
    try {
      backgroundURL = new java.net.URL("file:../java-programs/bg.jpg");
      craneURL = new java.net.URL("file:../java-programs/crane0002.jpg");
      assembleBoxURL = new java.net.URL("file:../java-programs/assemble box.jpg");
      driverRoomURL = new java.net.URL("file:../java-programs/driver room.jpg");
      hookURL = new java.net.URL("file:../java-programs/hook1.jpg");
      floorURL = new java.net.URL("file:../java-programs/floor2.jpg");
    }
    catch (java.net.MalformedURLException ex) {
      System.out.println(ex.getMessage());
      System.exit(1);
    }
    new MainFrame(new MyCraneFinal1(backgroundURL, craneURL,assembleBoxURL,driverRoomURL,hookURL,floorURL), 800, 480);
  }
}



