Contents / Previous / Next


Animator Example Program

// The base application is an Applet including a main function.
// The inner class JOGLFrame serves as wrapper for the applet.
// In this way JOGLbase may run as applet 
// or as application within an AWT Frame (JOGLFrame).
// Look at the main function to understand this.
public class JOGLbase extends Applet
  implements GLEventListener
{
  ...

  // Global canvas for event handling.
  GLCanvas canvas;

  // Vars for animation.
  FPSAnimator animator;

  ...

  // JOGLframe launch the applet as application.
  class JOGLframe extends Frame {

    public JOGLframe( JOGLbase base ) 
      {

	base.init();
	add( base );

	addWindowListener( new WindowAdapter() {
	    public void windowClosing( WindowEvent e ) {
	      System.exit(0); } 
	    // Canvas gets focus whenever frame is activated.
	    public void windowActivated( WindowEvent e ) {
	      //canvas.requestFocusInWindow(); 
	    }
	  } );

	setLocationRelativeTo(null);      
	setVisible( true );
	requestFocus();
	canvas.requestFocusInWindow();
	pack();

	// After JOGL and window setup, start the animator.
	animator = new FPSAnimator( canvas, 20 );
	animator.setRunAsFastAsPossible( false );
	animator.start();
      }
  }

  /////////////////////// main ///////////////////////

  public static void main( String[] args ) 
    {
      JOGLbase base = new JOGLbase();	
      JOGLbase.JOGLframe frame = base.new JOGLframe( base );
  }

 ....

}