//Create the OpenGL rendering canvas
GLCanvas canvas = new NormansAdventure();
canvas.setPreferredSize( new Dimension(CANVAS_WIDTH, CANVAS_HEIGHT));
// Create an animator that drives canvas' display() at the specified FPS
final FPSAnimator animator = new FPSAnimator(canvas, FPS, true);
//Create the top-level container
final JFrame frame = new JFrame(); // Swing's JFrame or AWT's Frame
frame.getContentPane().add(canvas);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
// Use a dedicated thread to run the stop() to ensure the animator
// thread stops before program exists.
new Thread() {
@Override
public void run() {
if (animator.isStarted()) animator.stop();
System.exit(0);
}
}.start();
}
});
frame.setTitle(TITLE);
frame.pack();
frame.setVisible(true);
animator.start(); // Start the animation loop
}
});
}