title: Why does my PolyLine keep drawing from origin (0,0)?
body: <p>I'm creating a <a href="https://en.wikipedia.org/wiki/Random_walk" rel="nofollow">RandomWalk</a> program. Most of the program is working as it should, however, there is one major issue.</p>
  
  <p>When the PolyLine is being drawn, it keeps being forced back to the origin (0,0) instead of where the last point was. I've been trying to see what I'm missing/doing wrong, but I can't locate the issue.</p>
  
  <p>Any help would be appreciated; if more info is needed, just ask. Thanks.</p>
  
  <p><strong>Main Class</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class RandomWalk {
      public static void main (String[] args) {
  
          // Creating main frame
          JFrame main = new JFrame("RandomWalk - Version 1.0");
          main.setSize(800, 800);
          main.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          main.setResizable(false);
          main.setLocationRelativeTo(null);
  
          // Creating content/container panel
          JPanel container = new JPanel();
          container.setLayout(new BoxLayout(container, BoxLayout.PAGE_AXIS));
          main.setContentPane(container);
  
          // Creating scene/canvas
          Draw canvas = new Draw();
          canvas.setAlignmentX(Component.CENTER_ALIGNMENT);
  
          container.add(canvas);
  
          main.toFront();
          main.setVisible(true);
      }
  }
  </code></pre>
  
  <p><strong>Drawing Class</strong></p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  import java.awt.event.*;
  
  public class Draw extends JPanel {
  
      // Starting value for i
      public static int i = 1;
  
      // Increment for line length
      public static int inc = 10;
  
      // Choose amount of lines/moves
      public static int a = 10000;
  
      // Arrays for polyline points
      public static int[] xPoints = new int[a];
      public static int[] yPoints = new int[a];
  
      public Timer timer = new Timer(5, new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              xPoints[0] = 400;
              yPoints[0] = 400;
  
              if (i &lt; a) {
  
                  double r = Math.random();
  
                  if (r &lt; 0.25) {
                      xPoints[i] = xPoints[i - 1] - inc;
                      yPoints[i] = yPoints[i - 1] - 0;
                      i++;
                  } else if (r &lt; 0.50) {
                      xPoints[i] = xPoints[i - 1] + inc;
                      yPoints[i] = yPoints[i - 1] + 0;
                      i++;
                  } else if (r &lt; 0.75) {
                      yPoints[i] = yPoints[i - 1] - inc;
                      xPoints[i] = xPoints[i - 1] - 0;
                      i++;
                  } else if (r &lt; 1.00) {
                      yPoints[i] = yPoints[i - 1] + inc;
                      xPoints[i] = xPoints[i - 1] + 0;
                      i++;
                  }
                  repaint();
              }
          }
      });
  
      public void paintComponent(Graphics g) {
  
          timer.start();
  
          g.drawPolyline(xPoints, yPoints, xPoints.length);
      }
  }
  </code></pre>