import javax.media.j3d.*;//
import javax.vecmath.*;
import java.awt.*;
import java.awt.event.*;
import com.sun.j3d.utils.geometry.*;
import com.sun.j3d.utils.universe.*;

public class RotatingCube extends Frame implements ActionListener
{ protected Button myButton=new Button("Exit");
private SimpleUniverse U1 = null;

protected BranchGroup buildContentBranch(Node Geometry_Appearance)
 {
BranchGroup BG_c=new BranchGroup();
Transform3D S1=new Transform3D();
S1.set(new AxisAngle4d(1.0,1.0,0.0,Math.PI/4.0));
TransformGroup TG_c=new TransformGroup(S1);
TG_c.setCapability
(TransformGroup.ALLOW_TRANSFORM_WRITE);
BG_c.addChild(TG_c);
TG_c.addChild(Geometry_Appearance);
Transform3D yAxis = new Transform3D();
Alpha rotationAlpha = new Alpha(-1,4000);
RotationInterpolator B1 = new RotationInterpolator
(rotationAlpha,TG_c,yAxis,0.0f,(float)Math.PI*2.0f);
BoundingSphere bounds=new BoundingSphere
(new Point3d(0.0,0.0,0.0),100.0);
B1.setSchedulingBounds(bounds);
TG_c.addChild(B1);
BG_c.compile();
return BG_c;
}
protected Node buildShape()
{
return new ColorCube(0.4);
}
public void actionPerformed(ActionEvent e)
{
dispose();
System.exit(0);
}//end actionPerformed

public RotatingCube()
{ GraphicsConfiguration
config=SimpleUniverse.getPreferredConfiguration();
Canvas3D Canvas3D_1=new Canvas3D(config);
BranchGroup scene=buildContentBranch(buildShape());
U1=new SimpleUniverse(Canvas3D_1);
U1.getViewingPlatform().setNominalViewingTransform();
U1.addBranchGraph(scene);
setTitle("RotatingCube");
setSize(600,600);
setLayout(new BorderLayout());
add("Center", Canvas3D_1);
add("South",myButton);
myButton.addActionListener(this);
setVisible(true);
}//end RotatingCube()

public static void main(String[] args)
{
RotatingCube rc=new RotatingCube();
}
}//end RotatingCube class