2012-03-31 118 views
0

這裏是我的代碼我的JOGL程序拒絕運行出了什麼問題?

公共類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

代碼總是產生以下錯誤

錯誤:無法找到或加載主類或g.yourorghere.SimpleJoglApp Java結果:1

我在做什麼錯?

+0

如何安裝jogl?檢查類路徑和路徑。 – Tofiq 2012-04-02 21:56:29

回答

0

您從未設置jframe.setvisible(true);

此外:錯誤:無法找到或加載主類org.yourorghere.SimpleJoglApp Java結果:1 與java無關。只需修復你的課程設置。