Advertisement

03.15.2007 at 04:48AM PDT, ID: 22451135
[x]
Attachment Details

JOGL using NetBeans

[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.2
I am trying to get familiar with JOGL but cannot seem to get around this little stumbling block. I downloaded demo code for the "Gears" demo from https://jogl-demos.dev.java.net/. The code works fine if used as is.

<<============ Trimmed version of the demo code =============>>
package joglapplication1;

/** imports and JavaDoc **/

public class Main implements GLEventListener, MouseListener, MouseMotionListener {
    public static void main (String[] args) {
        Frame frame = new Frame ("Gear Demo");
        GLCanvas canvas = new GLCanvas ();
       
        canvas.addGLEventListener (new Main ());
        frame.add (canvas);
        frame.setSize (300, 300);
        //final Animator animator = new Animator(canvas);
        frame.addWindowListener (new WindowAdapter () {
            public void windowClosing (WindowEvent e) {
                // Run this on another thread than the AWT event queue to
                // make sure the call to Animator.stop() completes before
                // exiting
                new Thread (new Runnable () {
                    public void run () {
                        //animator.stop();
                        System.exit (0);
                    }
                }).start ();
            }
        });
        frame.setVisible (true);
        //animator.start();
    }
   
    /** private variables **/

    public void init (GLAutoDrawable drawable) {...}
   
    public void reshape (GLAutoDrawable drawable, int x, int y, int width, int height) {...}
   
    public void display (GLAutoDrawable drawable) {...}
   
    public void displayChanged (GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {}
   
    public static void gear (GL gl, float inner_radius, float outer_radius, float width, int teeth, float tooth_depth) {...}
   
    // Methods required for the implementation of MouseListener
...
   
    // Methods required for the implementation of MouseMotionListener
...
}

As you can see, the GLCanvas is added to the Frame and occupies the whole display area. I want only a part of the frame to be displaying OpenGL stuff and want to use the rest for showing other information. So I create a custom class that extends JFrame; add a JPanel to it; and add GLCanvas to the JPanel instead to the form. Something great happens now and OpenGL stuff is nowhere to be seen.

To simplify stuff I removed the JPanel from MyFrame and added the GLCanvas directly to MyFrame. Still no result. Anyways, I finally figured that initComponents() being called from MyFrame ctor is the root cause because somehow it stops events from reaching the GLEventListener. I comment out the call to initComponents() and the wonderful gears show up. but then that defeats the whole purpose of the MyFrame and the GUI to design the form.

Here is the code for initComponents().
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                          
    private void initComponents() {
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
    }// </editor-fold>                        

The code for MyListener is unchanged except that main() is moved to a different file. My guess is that setting layout causes the problems. Any ideas how to reopen the channel to GLEventListener?
Answered By: jhshukla
Expert Since: 05/01/2003
Accepted Solutions: 192
Computer Expertise: Beginner
jhshukla has been an Expert for 5 years 8 months, during which he has posted 1207 comments and answered 192 questions. jhshukla is just one of 126 experts in the NetBeans IDE Zone. 1 expert collaborated on this answer, which was graded a "C" by the asker.
 
 
 
 
20081119-EE-VQP-48