Beginner Swing recursion
<p>This programming assignment has me stumped; the code is as follows:</p>
<pre><code>import java.awt.*;
import javax.swing.*;

public class HTree extends JPanel {

private Color color = new Color((int)(Math.random() * 256), (int)(Math.random() * 256), (int)(Math.random() * 256));

public void draw(Graphics g, int n, double sz, double x, double y) {
    if (n == 0) return; 
    double x0 = x - sz/2, x1 = x + sz/2;
    double y0 = y - sz/2, y1 = y + sz/2;
    // draw the 3 line segments of the H  
    g.setColor(color);
    g.drawLine((int)x0, (int)y, (int)x1, (int)y);
    g.drawLine((int)x0, (int)y0, (int)x0, (int)y1);
    g.drawLine((int)x1, (int)y0, (int)x1, (int)y1);
    // recursively draw 4 half-size
    // H-trees of order n-1
    g.setColor(color);
    draw(g, n-1, sz/2, x0, y0);
    draw(g, n-1, sz/2, x0, y1);
    draw(g, n-1, sz/2, x1, y0);
    draw(g, n-1, sz/2, x1, y1);
    repaint();
}

public void paintComponent(Graphics g) {
    super.paintComponent(g);
    draw(g, 3, .5, .5, .5);
}

public static void main(String[] args) {
    HTree h = new HTree();
    JFrame application = new JFrame(&quot;HTree&quot;);
    application.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    application.add(h);
    application.setSize(1000, 1000);
    application.setVisible(true);
}
}
</code></pre>
<p>It compiles correctly, but when running the program, all I get is an empty <code>JFrame</code>. I am not too familiar with Swing, but I think the problem is that either the <code>HTree</code> constructor is wrong, or I may need to call <code>draw()</code> in main—I'm not sure how to call it with a <code>Graphics</code> object. Any help is appreciated, Thank you!</p>