将GLCanvas添加到Java AWT Frame

时间:2013-07-10 06:52:23

标签: java opengl awt jogl

我正试图通过Justin Stoecker's JOGL Tutorials学习OpenGL基础知识。但是,当我尝试使用他描述的某些方法时,Eclipse会给我带来错误。

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);
            }
        });
    }
}

两个问题:第一个java.awt.Frame不允许GLCanvas作为add方法的参数。第二个问题是类似的,尝试使用addWindowListener方法会给出错误消息:“Window类型中的方法addWindowListener(WindowListener)不适用于参数(new WindowAdapter(){})。”我很困惑,因为这个代码在编写时显然有效。作为一般的JOGL和GUI编程的新手,我不确定我需要更改什么才能使其正确运行。

0 个答案:

没有答案
相关问题