Do not try to get it in the constructor, use this.HEIGHT and this.WIDTH and set it with
public void setLocation (int x, int y) method. Make sure you do this in the paintcomponent method, which you must override, so it calls it every time it is changed.
source share