Login  Register

Re: Outsmarted myself - JOGL instance variables in subclasses.

Posted by LordSmoke on Jan 14, 2017; 1:35pm
URL: https://forum.jogamp.org/Outsmarted-myself-JOGL-instance-variables-in-subclasses-tp4037578p4037582.html

I think I have it figured out. Not as code-minimizing a solution as I would have liked, but seems to work and may be what is necessary given the inheritance issues.

Solution - uniquely variables have to be instanced in each subclass with associated overridden get/set functions. That way, superclass methods using these functions will get/set the local version in the subclass. Haven't checked to see if they have to be uniquely named, but...

dialog01:
    class JOGLColor {
        float r = 0;
        float g = 0;
        float b = 0;
        JOGLColor( float red, float green, float blue ) {
            r = red;
            g = green;
            b = blue;
        }
    };
    // Some colors I like.
    final JOGLColor WHITE = new JOGLColor( 1f, 1f, 1f );
...
        JOGLColor demo01BGColor = BLACK;
    JOGLColor getBGColor() {
      return demo01BGColor;  
    };
    void setBGColor(float red, float green, float blue, boolean doRepaint) {
        demo01BGColor.r = red;
        demo01BGColor.g = green;
        demo01BGColor.b = blue;
        // Allow for resetting of background color without repainting.
        if (doRepaint) {
            glCanvas.repaint();
        }
    }

dialog02:
    JOGLColor demo02BGColor = new JOGLColor(DARKRED.r, DARKRED.g, DARKRED.b);
    JOGLColor getBGColor() {
      return demo02BGColor;  
    };
    void setBGColor(float red, float green, float blue, boolean doRepaint) {
        demo02BGColor.r = red;
        demo02BGColor.g = green;
        demo02BGColor.b = blue;
        // Allow for resetting of background color without repainting.
        if (doRepaint) {
            glCanvas.repaint();
        }
    }
   
dialog03:
    JOGLColor demo03BGColor = new JOGLColor( DARKGREEN.r, DARKGREEN.g, DARKGREEN.b);
    JOGLColor getBGColor() {
      return demo03BGColor;  
    };
    void setBGColor(float red, float green, float blue, boolean doRepaint) {
        demo03BGColor.r = red;
        demo03BGColor.g = green;
        demo03BGColor.b = blue;
        // Allow for resetting of background color without repainting.
        if (doRepaint) {
            glCanvas.repaint();
        }
    }

Will have to do the same for glCanvas in above and a set of other variables, but will put everything between comment blocks to note this is a Java requirement and not anything JOGL/OpenGL specific.