Getting Started - Your First Program

The following program shows you the basic steps needed to display 3D objects.

  1. Create a virtual universe to contain your scene.
  2. Create a data structure to contain a group of objects.
  3. Add an object to the group
  4. Position the viewer so that they are looking at the object
  5. Add the group of objects to the universe


Look at the Hello3d() constructor and you will see the five lines that perform each of these steps. The program displays a glowing cube, the viewer is looking directly at the red face of the cube, so what you actually see is a red square on a black background


import com.sun.j3d.utils.universe.SimpleUniverse;

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


public class Hello3d {

public Hello3d()


   SimpleUniverse universe = new SimpleUniverse();

   BranchGroup group = new BranchGroup();

   group.addChild(new ColorCube(0.3));




public static void main( String[] args ) {

   new Hello3d();


} // end of class Hello3d

The import statements at the beginning of this program use various parts of Java 3D, so compiling and running this program is a good test that you have installed Java 3D correctly.

Introduction <<< Table of Contents >>> Lighting up the World