我的JOGL程序拒绝运行出错的地方?

时间:2012-03-31 13:37:43

标签: jogl mainclass

这是我的代码

公共类SimpleJoglApp扩展了JFrame {

public static void main(String[] args) {
    final SimpleJoglApp app = new SimpleJoglApp();

    // show what we've done
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            app.setVisible(true);
        }
    });
}


public SimpleJoglApp() {

    // set the JFrame title
    super("Test App");

    // kill the process when the JFrame is closed
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // only two JOGL lines of code ... and here they are
    GLCanvas glcanvas = new GLCanvas();

    glcanvas.addGLEventListener(new SecondGLEventListener());

    // add the GLCanvas just like we would any Component
    getContentPane().add("Center", glcanvas);
    setSize(500, 300);
}



public void centerWindow(Component frame) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize  = frame.getSize();

    if (frameSize.width > screenSize.width) {
        frameSize.width = screenSize.width;
    }

    if (frameSize.height > screenSize.height) {
        frameSize.height = screenSize.height;
    }

    frame.setLocation((screenSize.width - frameSize.width) >> 1, (screenSize.height - frameSize.height) >> 1);
}

public class SecondGLEventListener implements GLEventListener {

    /**
     * Interface to the GLU library.
     */
    private GLU glu;

    public void init(GLAutoDrawable drawable) {
        GL gl = drawable.getGL();

        glu = new GLU();
        gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        gl.glViewport(0, 0, 500, 300);
        gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluOrtho2D(0.0, 500.0, 0.0, 300.0);
    }

    /**
     * Take care of drawing here.
     */
    public void display(GLAutoDrawable drawable) {
        float red   = 0.0f;
        float green = 0.0f;
        float blue  = 0.0f;
        GL    gl    = drawable.getGL();

        gl.glClear(GL.GL_COLOR_BUFFER_BIT);
        gl.glPointSize(20.0f);

        for (int i = 0; i < 10; i++) {
            red   -= .09f;
            green -= .12f;
            blue  -= .15f;

            if (red < 0.50) {
                red = 0.5f;
            }

            if (green < 0.15) {
                green = 0.5f;
            }

            if (blue < 0.15) {
                blue = 0.5f;
            }

            gl.glPushMatrix();
            gl.glColor3f(red, green, blue);
            gl.glTranslatef(10.0f, 500.0f, 0.0f);           // Move left 1.5 units, up 1.5 units, and back 8 units
            gl.glBegin(GL.GL_QUADS);                        // Begin drawing quads
            gl.glVertex3f((10f * i) + 10, 20.0f, 0.0f);     // Top left vertex
            gl.glVertex3f((40f * i) + 10, 20f, 0.0f);       // Top right vertex
            gl.glVertex3f((40f * i) + 10, -20f, 0.0f);      // Bottom right vertex
            gl.glVertex3f((10f * i) + 10, -20.0f, 0.0f);    // Bottom left vertex
            gl.glEnd();
            gl.glPopMatrix();
        }
    }

    public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {}

    public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
}

}

` //〜由Jindent格式化--- http://www.jindent.com

代码总是产生以下错误

错误:无法找到或加载主类org.yourorghere.SimpleJoglApp Java结果:1

我做错了什么?

1 个答案:

答案 0 :(得分:0)

你永远不会设置jframe.setvisible(true);

另外:错误:无法找到或加载主类org.yourorghere.SimpleJoglApp Java结果:1 与java无关。只需修复你设置的课程。