Question

here is my code

public class SimpleJoglApp extends 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) {}
}

}

` //~ Formatted by Jindent --- http://www.jindent.com

the code always produces the following error

Error: Could not find or load main class org.yourorghere.SimpleJoglApp Java Result: 1

What am i doing wrong?

Was it helpful?

Solution

You never set the jframe.setvisible(true);

Also: Error: Could not find or load main class org.yourorghere.SimpleJoglApp Java Result: 1 has nothing to do with java. Just fix your classes set up.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top