0

I'm trying to learn OpenGL basics via Justin Stoecker's JOGL Tutorials. However Eclipse gives me errors when I try to use some of the methods as he describes.

public class RenderingTest {
    public static void main(String[] args) {
        GLProfile glp = GLProfile.getDefault();
        GLCapabilities caps = new GLCapabilities(glp);
        GLContext con = GLContext.getCurrent() ;
        GLCanvas canvas = new GLCanvas(canvas, 0, caps, null, con);

        Frame frame = new Frame("AWT Window Test");
        frame.setSize(300, 300);
        frame.add(canvas); //doesn't compile
        frame.setVisible(true);

        frame.addWindowListener(new WindowAdapter() { //doesn't compile
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
    }
}

Two problems: first java.awt.Frame won't allow a GLCanvas as an argument for the add method. The second problem is similar, attempting to use the addWindowListener method gives the error message: "The method addWindowListener(WindowListener) in the type Window is not applicable for the arguments (new WindowAdapter(){})." I'm confused because this code obviously worked when it was written. Being completely new to JOGL and GUI programming in general, I'm not sure what I need to change to make this run correctly.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
AdamJames
  • 367
  • 2
  • 11
  • 1
    Why AWT rather than Swing? See this answer on [Swing extras over AWT](http://stackoverflow.com/a/6255978/418556) for many good reasons to abandon using AWT components. If you need to support older AWT based APIs, see [Mixing Heavyweight and Lightweight Components](http://www.oracle.com/technetwork/articles/java/mixing-components-433992.html). Note 1) That the `WindowListener` shiwn is unnecessary in a `JFrame` since it has a `setDefaultCloseOperation(int)` method with a value that does just that, & 2) a) People don't really care if AWT breaks (e.g. 'use Swing') b) Even if they care, it is.. – Andrew Thompson Jul 10 '13 at 07:35
  • ..hard to remember the fine detail! – Andrew Thompson Jul 10 '13 at 07:38
  • @Andrew Thompson all code, frameworks, 3rd. sides API for OpenXxx & 3D, CAD/CAM, Html5 (by ignoring that JavaFX exist) can be based on AWT only, Swings addons can't rendering those Objects, EDIT too long that I played with, – mKorbel Jul 10 '13 at 07:48

0 Answers0