Lesson 1: Hello JME! Writing your first JME applet.

Return to the home page

The goal:

Not very exciting yet, is it? Click to see full size

Click here to download the code. (If the page opens in the broswer, you can right click on link and click "Save Link As", or right click on the page and click "Save As")

        	// most applications will want to extend the SimpleGame class
            import com.jme.app.SimpleGame;
            
            /* SimpleGame extends BaseSimpleGame, which extends BaseGame,
               which extends AbstractGame. (All four of these classes are abstract.)
               One advantage to using SimpleGame is that code easily translates
               into SimpleApplet,
               useful for program deployment. */
            
            /* BaseSimpleGame implements (among other things):
            
               The basic game loop (update and render),
               an input manager to keep track of keyboard and mouse actions,
               a root node to which all scene elements will be attached.
              
               Lines 436--472
                F1 - Take screenshot;        F4  - Toggle performance statistics;
                T  - Toggle wireframe;       L   - Toggle lights;
                N  - Toggle normal vectors;  B   - Toggle bounding surfaces;
                P  - Pause update loop;      Esc - Exit program
              
               Lines 391--421
                 A Camera at (0,0,25) oriented with y-axis as up and facing the origin;
              
               Lines 423--426
               A First-Person style input handler (WASDQZ, ArrowKeys, and Mouse)
              
               Lines 506--513
                 A ZBuffer to display pixels that are closer on top of those further away;
              
               Lines 530--542
                 A PointLight at (100,100,100); */
            
            // a vector containing three float numbers;
            //   used to store positions and translations
            import com.jme.math.Vector3f;
            
            // geometric shapes used in program
            import com.jme.scene.shape.Box;
            
            public class First extends SimpleGame
            {
               // a geometric shape that will be rendered
               Box myBox;
            
               public static void main(String[] args)
               {
                   // create an instance of this program
                   First app = new First();
            
                   // before the main program starts, display the graphics configuration window
                   //   where the user can choose among screen resolution, color depth, and full screen options
                   app.setConfigShowMode(ConfigShowMode.AlwaysShow);
            
                   // The start() method runs:
                   //     initSystem()
                   //     initGame()   ->  calls simpleInitGame(), created by programmer
                   //     then start the game loop, which loops through
                   //        update()  ->  calls simpleUpdate(), created by programmer
                   //        render()  ->  calls simpleRender(), created by programmer
                   //     after finish() is called, game loop will end,
                   //     then cleanup() is called to dispose of resources, etc.
                   app.start();
               }
            
               protected void simpleInitGame()
               {
                   // Parameters for the Box constructor:
                   //   Box( String name, Vector3f center, float xRadius, float yRadius, float zRadius )
                   myBox = new Box("b", new Vector3f(1,1,1), 3, 3, 3);
            
                   // attach this object to the root node so that it will be rendered
                   rootNode.attachChild( myBox );
               }
            
               protected void simpleUpdate()
               {
                   // nothing to add
               }
            
               protected void simpleRender()
               {
                   // nothing to add
               }
            }
        

Return to the home page