/Users/lyon/j4p/src/j3d/cr325/Hello/HelloJava3Da.java

1    package j3d.cr325.Hello; 
2     
3     
4    import com.sun.j3d.utils.applet.MainFrame; 
5    import com.sun.j3d.utils.geometry.ColorCube; 
6    import com.sun.j3d.utils.universe.SimpleUniverse; 
7     
8    import javax.media.j3d.BranchGroup; 
9    import javax.media.j3d.Canvas3D; 
10   import java.applet.Applet; 
11   import java.awt.*; 
12    
13   //   HelloJava3Da renders a single, rotating cube. 
14    
15   public class HelloJava3Da extends Applet { 
16       public HelloJava3Da() { 
17           setLayout(new BorderLayout()); 
18           GraphicsConfiguration config = 
19                   SimpleUniverse.getPreferredConfiguration(); 
20    
21           Canvas3D c3d = new Canvas3D(config); 
22           add("Center", c3d); 
23    
24           BranchGroup bg = getBranchGroup(); 
25    
26           // SimpleUniverse is a Convenience Utility class 
27           SimpleUniverse su = new SimpleUniverse(c3d); 
28    
29           // This will move the ViewPlatform back a bit so the 
30           // objects in the scene can be viewed. 
31           su.getViewingPlatform().setNominalViewingTransform(); 
32    
33           su.addBranchGraph(bg); 
34       } // end of HelloJava3Da (constructor) 
35    
36       public BranchGroup getBranchGroup() { 
37           // Create the root of the branch graph 
38           BranchGroup bg = new BranchGroup(); 
39    
40           bg.addChild(new ColorCube(.3)); 
41           bg.compile(); 
42    
43           return bg; 
44       } // end of CreateSceneGraph method of HelloJava3Da 
45    
46       //  The following allows this to be run as an application 
47       //  as well as an applet 
48    
49       public static void main(String[] args) { 
50           new MainFrame(new HelloJava3Da(), 256, 256); 
51       } // end of main (method of HelloJava3Da) 
52    
53   } // end of class HelloJava3Da 
54