title: Recursive Sierpinsky Triangle - StackOverflow error
body: <p>I got my code running so far, except for the recursive part. I get a StackOverflow error and I really don't get why, or how to fix it. When I work through the code it seems logically fine.</p>
  
  <pre><code>public class SierpinskiTriangle {
  public static int SIZE = 1000;
  
  JFrame frame;
  JPanel panel;
  
  @SuppressWarnings("serial")
  public void display() {
      frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      panel = new JPanel() {
          @Override
          public void paint(Graphics g) {
              super.paint(g);
              paintSierpinskiTriangle(20, 20, 360, (Graphics2D)g);
          }
      };
      panel.addComponentListener(new ComponentAdapter() {
          @Override
          public void componentResized(ComponentEvent e) {
              panel.repaint();
          }
      });
      frame.setLayout(new BorderLayout());
      frame.add(panel, BorderLayout.CENTER);
      frame.pack();
      frame.setSize(SIZE, SIZE);
      frame.setVisible(true);
  }
  
  public static void main(String[] args) {
      SierpinskiTriangle triangle = new SierpinskiTriangle();
      triangle.display();
  }
  
  public static void paintSierpinskiTriangle(int x, int y, int s, Graphics2D g) {
      g.drawLine(x, y, x+s, y);
      g.drawLine(x, y, x, y+s);
      g.drawLine(x+s, y, x, y+s);
  
      paintSierpinskiTriangle(x, y, s/2, g);
      paintSierpinskiTriangle(x+s/2, y, s/2, g);
      paintSierpinskiTriangle(x, y+s/2, s/2, g);
  
  }
  }
  </code></pre>