I know web pages should be past this, but this site doesn't look right on IE.
I will fix it some day ( not for IE 6 though) but for now this is easier and a lot more fun.

Download firefox or chrome or hide this message forever...

Separating the View from the JFrame.




You may want to separate the GLActionListener from the JFrame in your programs. Maybe you want to change the listener as your programs continues, have multiple views, or you just want to keep your code clean.


  • First create a class that extends JFrame, we will call it MyController.
  • Then, create a class that implements GLActionListener. Let's call it MyViewer
  • In the constructor of MyController, do the following:
    • Create a GLCanvas
    • Set its GLActionListener to an instance of MyViewer
    • Add the GLCanvas to the MyController.
      • Don't forget if you are using BorderLayout to add it to the center of the layout.
  • In order to refresh the display in this program, I used the FPSAnimator class. This class automatically refreshes the canvas.
    • Create a class level variable of the FPSAnimator.
    • Instantiate the FPSAnimator before your add the canvas to MyController.
      • FPSAnimator = new FPSAnimator(GLCanvas,int TARGET_FPS, boolean TODO);
    • Start the FPSAnimator
  • In MyViewer, setup OpenGL like you normally would.