import java.awt.*;
import javax.swing.*;
public class Snake extends JPanel
{
    JFrame mainFrame;
    int[][] knots;
    int currend;
    int s = 500;
    int length;
    public Snake()
    {
        mainFrame = new JFrame();
        mainFrame.setSize(1000,1000);
        
        this.setBounds(0,0,1000,1000);
        mainFrame.add(this);
        this.setVisible(true);
        mainFrame.setVisible(true);
        int[][] knots = {{s,s},{s,s},{s,s},{s,s},{s,s},{s,s},{s,s}};
        length = knots.length;
        this.knots = knots;

        System.out.println(knots.length);
        System.out.println(knots[0].length);
        
        currend = 0;
    }

    public void start(){
        while(true){
            try {
                Thread.sleep(250);
                update();
                this.repaint();
                mainFrame.repaint();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    
    public void update(){
        int last = currend;
        currend = (currend+1)%length;
        knots[currend][0] =(knots[last][0] + (Math.abs((int)(Math.random() * 100)) -50)%1000);
        knots[currend][1] =(knots[last][1] + (Math.abs((int)(Math.random() * 100)) -50)%1000);
    }

    public void paint(Graphics g){
        System.out.println("paint");
        g.setColor(Color.black);
        for(int i = 0; i<length-1; i++){
            System.out.println((currend +i)%length + "-->" +(currend +i +1)%length);
            g.drawLine(knots[(currend +i)%length][0], knots[(currend +i)%length][1], knots[(currend +i+1)%length][0], knots[(currend +i+1)%length][1]);
        }
        g.setColor(Color.white);
        //g.drawLine(knots[(currend +length-2)%length][0], knots[(currend +length-2)%length][1], knots[(currend +length-1)%length][0], knots[(currend +length-1)%length][1]);
    }
}

@@ -425,16 +425,258 @@
  knots =
+ new int%5B7%5D%5B2%5D;%0A        int%5B%5D%5B%5D knots_old = new int%5B7%5D%5B2%5D;%0A        for(int x = 0; x %3C knots.length; x++)%7B%0A            for(int y = 0; y %3C knots%5Bx%5D.length; y++)%7B%0A                knots%5Bx%5D%5By%5D = s;%0A            %7D%0A        %7D%0A        //int%5B%5D%5B%5D knots =
  %7B%7Bs,s%7D,
@@ -1336,20 +1336,34 @@
 =(knots%5B
-last
+(currend+1)%25length
 %5D%5B0%5D + (
@@ -1399,30 +1399,30 @@
 * 100)) -50)
+)
 %251000
-)
 ;%0A        kn
@@ -1445,20 +1445,34 @@
 =(knots%5B
-last
+(currend+1)%25length
 %5D%5B1%5D + (
@@ -1516,14 +1516,14 @@
 -50)
+)
 %251000
-)
 ;%0A  

Fix the error