Java anonymous class
<p>I am bit lost with the anonymous classes in Java, I've read about them, but how can I use this class:</p>

<pre><code>private abstract class CustomRectangle {
    protected final int width;
    protected final int height;
    protected final int xOffset;
    protected final int yOffset;
    protected final int borderSize;

    public CustomRectangle(final int width, final int height, final int xOffset, final int yOffset, final int borderSize) {
        this.width = width;
        this.height = height;
        this.xOffset = xOffset;
        this.yOffset = yOffset;
        this.borderSize = borderSize;
    }

    abstract void inBorder(final int dx, final int dy);

    abstract void outBorder(final int dx, final int dy);

    public void draw(Graphics2D g2d) {
        for (int x = 0; x &lt; width; x++) {
            for (int y = 0; y &lt; height; y++) {
                int dx = Math.min(x, width - 1 - x);
                int dy = Math.min(y, height - 1 - y);
                if (dx &lt; borderSize || dy &lt; borderSize) {
                    inBorder(dx, dy);
                }
                else {
                    outBorder(dx, dy);
                }
                g2d.drawLine(x + xOffset, y + yOffset, x + xOffset, y + yOffset);
            }
        }
    }
}
</code></pre>

<p>In another method to do the following things at the same time:</p>

<ol>
<li>Extend the CustomRectangle to override InBorder() and outBorder()</li>
<li>Draw the new CustomRectangle by invoking the draw() method.</li>
</ol>

<p>There must be an easy way for doing this and I do not feel like making a ton of classes for every time I want to draw a CustomRectangle.</p>

<p>Help is appreciated :)</p>

<p><strong>EDIT including solution:</strong></p>

<pre><code>    new CustomRectangle(CARD_DIMENSION.width, CARD_DIMENSION.height, 0, 0, 5) {
        @Override
        public void inBorder(final int dx, final int dy) {
            g2d.setColor(new Color(red, green, blue, 255 - Math.min(dx, dy)));
        }

        @Override
        public void outBorder(final int dx, final int dy) {
            g2d.setColor(new Color(red, green, blue, 192 - Math.min(dx, dy)));
        }
    }.draw(g2d);
</code></pre>

<p>Maybe it does not look that pretty, but it comes in pretty handy in the design of my application.</p>
