title: painting on JPanel line is not connected
body: <p>I was trying to make a chart using the JPanel paint method with Graphics2D draw shape. However, my lines are not connected and they have a slope of 0. My expectation was plotting the line like a signal wave. Here is my code:</p>
  
  <pre><code>package action;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  import java.awt.Toolkit;
  import java.awt.geom.Line2D;
  import java.util.Random;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class Starter extends JFrame {
  double Xoffset = 30, Yoffset = 20, Xold = 40, Ycurr = 40, Xcurr = Xold, 
  Ytarget = Ycurr, Xgap = 10, Ygap = 60;
  double sh = Toolkit.getDefaultToolkit().getScreenSize().getHeight();
  double sw = Toolkit.getDefaultToolkit().getScreenSize().getWidth();
  int panelOffSet = 20;
  
  double[] value_old = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
  double[] value_curr = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 
  };// new
  
  // double[17];
      int counter = 0;
  
  public static void main(String[] args) {
      // TODO Auto-generated method stub
      Starter mainThread = new Starter();
  }
  
  public Starter() {
      super("EEG Recorder");
      // //set the frame to center of screen
      setLayout(null);
      this.getContentPane().setBackground(new Color(32, 32, 32));
      setSize((int) sw, (int) sh);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      // add the painting panel
      EEGRecorder plotter = new EEGRecorder();
      add(plotter);
      this.setVisible(true);
      while (true) {
          plotter.run();
      }
  }
  
  class EEGRecorder extends JPanel implements Runnable {
  
      public EEGRecorder() {
          setLayout(null);
          setBackground(new Color(32, 32, 32));
          setBounds(0, panelOffSet, (int) sw, (int) (sh - panelOffSet));
      }
  
      @Override
      public void run() {
          // TODO Auto-generated method stub
          try {
              this.updateUI();
              repaint();
              Thread.sleep(50);
          } catch (InterruptedException e) {
              e.printStackTrace();
          }
          // System.out.println("hello");
      }
  
      @Override
      public void paint(Graphics g) {
          Graphics2D gg = (Graphics2D) g;
          for (int i = 1; i &lt; 17; i++) {
  
              Random rn = new Random();
              Ytarget = rn.nextDouble() * 30;
              value_curr[i] = Ytarget;
              // System.out.println(value_curr[i]);
  
              if (Xcurr + Xgap - 1 &gt; sw) {
                  gg.clearRect((int) Xoffset, (int) Yoffset, (int) (sw - Xoffset - 20), (int) (sh - panelOffSet));
                  gg.setColor(new Color(32, 32, 32));
                  gg.fillRect(0, 0, (int) (sw), (int) (sh - panelOffSet));
                  Xold = Xoffset;
                  Xcurr = Xold + Xgap;
              } else {
                  gg.setColor(Color.yellow);
                  gg.drawString("ch" + i, 4, (int) (Yoffset + (i - 1) * Ygap));
                  if (counter == 0) {
                      value_old[i] = 0;// value_curr[i];
                      Xcurr = Xold + Xgap;
  
                  }
                  gg.setColor(Color.BLUE);
                  gg.draw(new Line2D.Double(Xold, (i - 1) * Ygap - value_old[i], Xcurr,
                          (i - 1) * Ygap - value_curr[i]));
                  double Yold=(i - 1) * Ygap - value_old[i];
                  double Ynew=(i - 1) * Ygap - value_curr[i];
                  System.out.println(Xold+","+Yold+","+ Xcurr+","+Ynew);
              }
          }
  
          value_old = value_curr;
  
          // Ycurr = Ytarget;
  
          Xold = Xcurr;
          Xcurr += Xgap;
          counter++;
      }
  }
  </code></pre>
  
  <p>}</p>