Ignored MouseEvent

Hi everyone!

I’m new at jogl and trying to make something like a small 2D paint program. The trouble is that my sweet little program ignores my wish to paint when I try to do even the simplest thing, i.e. a line.

I am using GLCanvas with Animator. MouseListener and the other Standard Listeners are also added, but still nothing seems to work. I’ll just show you the important parts of the code:


    public void init(GLDrawable glDrawable)
    {
        
          final GL gl = glDrawable.getGL();
            final GLU glu = glDrawable.getGLU();
            
            int screenX = (int)Toolkit.getDefaultToolkit().getScreenSize().getWidth();
            int screenY = (int)Toolkit.getDefaultToolkit().getScreenSize().getHeight();
            
            gl.glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
            
            
            gl.glLineWidth(2.0f);
            gl.glPointSize(2.0f);
            
            gl.glViewport(0, 0, screenX - 110, screenY - 50);
            gl.glMatrixMode(GL.GL_PROJECTION);
            gl.glLoadIdentity();
            glu.gluOrtho2D(0.0, screenX - 110.0, 0.0, screenY - 50.0);
            gl.glClear(GL.GL_COLOR_BUFFER_BIT);
       
            //Events Listeners are registeres
            glDrawable.addGLEventListener(this);
            glDrawable.addKeyListener(this);
            glDrawable.addMouseListener(this);
            glDrawable.addMouseMotionListener(this);


    }

public void display(GLDrawable glDrawable)
    {
        
          final GL gl = glDrawable.getGL();
        final GLU glu = glDrawable.getGLU();

      gl.glMatrixMode(GL.GL_MODELVIEW);
      gl.glLoadIdentity();
}

    public void mouseClicked(MouseEvent e){
          
          Point linePT1 = new Point(0,0);
          Point linePT2 = new Point(0,0);
          int xPos, yPos;
          
          
          xPos = e.getX();
            yPos = e.getY();
            
            if (clickCounter == 0){
                  linePT1 = new Point(xPos, yPos);
                  clickCounter++;
                  
            }
            else if(clickCounter == 1){
                                                
                  linePT2 = new Point(xPos, yPos);
                  GL gl = canvas.getGL();
                  
                  //Select and initialise the Modelview Matrix
                  gl.glMatrixMode(GL.GL_MODELVIEW);
                  gl.glLoadIdentity();
                  
                  // set color to black
                  gl.glColor3f(0f, 0f, 0f);
                  
                  System.out.println("vor glBegin()");
                  gl.glBegin(GL.GL_LINES);
                        gl.glVertex2i(linePT1.x, linePT1.y);
                        gl.glVertex2i(linePT2.x, linePT2.y);
                  gl.glEnd();
                  
                  
                  
                  System.out.println("nach glEnd()");
                  
                  linePT1 = null;
                  linePT2 = null;
                  
                  clickCounter = 0;
            }
            
            canvas.repaint();
          
    }

Probably there’s just something pretty tiny stupid thing missing, but since I am just a newbie…

Found a solution to the problem so please ignore or delete…