Login  Register

Re: key input Keylistener doesn't work for JOGL

Posted by tragic_xxx on Nov 09, 2017; 5:55pm
URL: https://forum.jogamp.org/key-input-Keylistener-doesn-t-work-for-JOGL-tp4038300p4038309.html

gouessej wrote
Maybe you should have looked at the simple examples in the wiki.

Replace "this.addKeyListener(this);" by "canvas.addKeyListener(this);".

You can create the GLU instance in the method GLEventListener.init(GLAutoDrawable):
    @Override
    public void init(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        glu = GLU.createGLU(gl);

I disagree with your answer to jmaasing. You must understand the concepts before applying them, otherwise you will just tinker some source code that you don't really understand. I simply advised you to add the key listener to the canvas rather than to the frame; if you don't succeed in understanding that it means that you have to modify just a single line of code to achieve this, it means that you don't even understand the source code you originally posted. We didn't speak to you only about the theory, we explained to you how to fix your code and why it works. Moreover, the Oracle tutorials are very well written, they explain the concepts and they contain numerous examples (including full source code most of the time), it's not just about theory. I'm sure that if you try to learn too much things too fast, you'll fail. There are no shortcomings, neither in Swing nor in computer graphics in general.

In my humble opinion, giving you the fixed source code without being sure that you understand both the original one and the fixed one instead of giving you the fixes with the necessary explanations is a bad solution and leads to spoon-feeding. We weren't born experts, we became experts, keep it in mind.
MANY THANKS Julien!
I didn't even know you meant just one line modification, actually I had to change a few more lines to get it working.
I don't disagree at all, what i'm just saying is for newbies the two go hand in hand otherwise terminologies become like abstracts. But once concepts are consolidated then i can understand terminologies without snippets

On the other hand I may be guilty of being very impatient to spend a lot time on the detail theory of how swing combines with Java OpenGL due to the fact that I'm actually working on a large project and this is just a very small part of it. Its actually an Android project and I'm porting the renderer to desktop so I can carry visual debugging better. Such debugging on Android device is nightmare at the moment and emulator is useless in this case

I have taken your advice onboard, Many Thanks