
    package microtubule;

    import javax.swing.*;
    import java.awt.*;
    import java.awt.Graphics;
    import java.util.Random;
  
    public class MT extends JApplet {
    int width, height;
    int pointx=50, pointy=50;
    int cellwidth=30, cellheight=30;
    int rectwidth, rectheight;
    int xlength, ylength;
    
    int[][] matrix;
    double S= 1000;
    double L=0;
    double dt=1;
    int C=0;

    double v_plus =5.5;
    double v_minus =11.0;
    double Pc=0.3;
    double Pr=0.4;
    private double randnum;
    Random generator=new Random();
    int x1=10,y1=50,x2,y2;
   // private double x, y;

    String x="heagawghee".toUpperCase(), y="pawheae".toUpperCase();
   
    public void init() {
    System.out.println("Initializing applet");
    }
    public void start()
    {
    System.out.println("Start method call");
    }
    public void stop()
    {
    System.out.println("Stop");
    }
    public void destroy()
    {
    System.out.println("destroy");
    }

     public int[][] getMatrix()
    {
    return matrix;

    }


    public void paint(Graphics g)
    {

    xlength=x.length();
    ylength=y.length();
    rectwidth=(2+xlength)*cellwidth;
    rectheight=(2+ylength)*cellheight;
  

    int changexorigin=pointx;
    int changeyorigin=pointy;
    changexorigin+=cellwidth;
    changeyorigin+=cellheight;
x1=changexorigin;y1=pointy+rectheight-10;
    g.drawLine(changexorigin, pointy, changexorigin, pointy+rectheight);
    g.drawLine (changexorigin, pointy+rectheight, changexorigin+rectheight+280, pointy+rectheight);
    g.drawString("Length", changexorigin-80, (pointy+rectheight)/2);
    g.drawString("Time", (pointy+rectheight), (pointy+rectheight+40));
//     g.drawSpot("Length", changexorigin-80, (pointy+rectheight)/2);
//    g.drawString("Time", (pointy+rectheight), (pointy+rectheight+40));


    matrix=new int[y.length()+1][x.length()+1];
    matrix[0][0]=0;
    g.drawString(""+matrix[0][0], pointx+cellwidth+cellwidth-70/2, pointy+cellheight+cellheight+450/2);


    int a=rectheight/5;
    for(int i=1;i<=10;i+=1)
    {
        g.drawString(""+i, changexorigin+a, (pointy+rectheight+15));
        //g.drawLine(changexorigin, pointy, changexorigin, pointy+rectheight);
        changexorigin+=a;
    }
    changexorigin=pointx;


    a=rectheight/10;
    for(int j=1;j<=10;j++)
    {
        g.drawString(""+j,changexorigin+10,pointy+rectheight-a);
        //g.drawLine(pointx, changeyorigin, pointx+rectwidth, changeyorigin);
        rectheight-=a;
    }
L=0;
    for (int t=1;t<=10;t++)
         {

             if(C==1)
             {
                 L=L-v_minus*dt;
             }
             if(C==0)
             {
                 L=L+v_plus*dt;
             }

             x2=(int)(x1+50);y2=(int)(y1+L+50); //change in x and y are so small, so add 50 to see the change
             System.out.println("Length before random "+L);
             randnum= generator.nextDouble();
             System.out.println("Random number is "+ randnum);
//             if(t%2==0)
//             {
//                 C=1;
//             }
//             else
//             {
//                 C=0;
//             }
             if(C==1 && randnum<(Pr*dt))
             {
                 C=0;
             }
             if(C==0 && randnum<(Pc*dt))
             {
                 C=1;
             }

             System.out.println("Value of length is : "+ L);

             g.drawLine(x1, y1,x2,y2);
             g.drawString(""+t, x2, y2);

             x1=x2;y1=y2;
       }
     }
   }