import java.awt.*;
import java.applet.*;

public class Neko extends Applet implements Runnable
{

    public static void main (String args[])
    {
    Image nekopics[] = new Image[9];
        Image currentimg;
        Thread runner;
        int xpos;
        int ypos = 50;  

        public void init()
        {
            String nekosrc[] = {"right1.gif" , "right2.gif" , "stop.gif" , "yawn.gif" , "scratch1.gif" , "scratch2.gif" , "sleep1.gif" , "sleep2.gif" , "awake.gif"};

            for(int i=0 ; i<nekopics.length ; i++)
            {
                nekopics[i] = getImage(getCodeBase(),"images/" + nekosrc[i]);
            }
        }

        public void start()
        {
            if (runner == null)
            {
                runner = new Thread(this);
                runner.start();
            }
        }

        public void stop()
        {
            if (runner != null)
            {
                runner.stop();
                runner = null;
            }
        }

        public void run()
        {
            setBackground(Color.white);

            //run from one side of screen to middle
            nekorun(0 , this.size().width/2);

            //stop and pause
            currentimg = nekopics[2];
            repaint();
            pause(1000);

            //yawn
            currentimg = nekopics[3];
            repaint();
            pause(1000);

            //scratch four times
            nekoscratch(4);

            //sleep for 5 "turns"
            nekosleep(5);

            //wake up and runoff
            currentimg = nekopics[8];
            repaint();
            pause(500);
            nekorun(xpos,this.size().width+10);
        }

        void nekorun(int start , int end)
        {
            for(int i=start;i<end;i+=10)
            {
                this.xpos = i;
                //swap images
                if(currentimg == nekopics[0])
                currentimg = nekopics[1];

                else if(currentimg == nekopics[1])
                currentimg = nekopics[0];
                else currentimg = nekopics[0];

                repaint();
                pause(150);

            }
        }

        void nekoscratch(int numtimes)
        {
            for(int i=numtimes ; i>0 ; i--)
            {
                currentimg = nekopics[4];
                repaint();
                pause(150);

                currentimg = nekopics[5];
                repaint();
                pause(150);

            }
        }

        void nekosleep(int numtimes)
        {
            for(int i=numtimes ; i>0 ; i--)
            {
                currentimg = nekopics[6];
                repaint();
                pause(250);

                currentimg = nekopics[7];
                repaint();
                pause(250);
            }
        }

        void pause(int time)
        {
            try
            {Thread.sleep(time);}
            catch(InterruptedException e){}
        }

        public void paint(Graphics g)
        {
            g.drawImage(currentimg,xpos,ypos,this);
        }
    }   
}

it shows illegal start of expression & ; expected.....whats the problem??

On what line number?

wherever i start a new method....on that line i get an illegal start of expression error & ';' expected.....m also facing the same problem in many other programs of applets.
Plz help me out. Thnx a ton

You are missing the closing bracket on your main method (should be on line 14). You can't start a new method inside another method, not even the main method.

import java.awt.*;
import java.applet.*;

public class Neko extends Applet implements Runnable
{
    Image  nekopics[] = new Image[9];
        Image currentimg;
        Thread runner;
        int xpos;
        int ypos = 50;
    public static void main(String args[])
    {       
        Neko n = new Neko();
    }   
        public void init()
        {
            String nekosrc[] = {"right1.gif" , "right2.gif" , "stop.gif" , "yawn.gif" , "scratch1.gif" , "scratch2.gif" , "sleep1.gif" , "sleep2.gif" , "awake.gif"};

            for(int i=0 ; i<nekopics.length ; i++)
            {
                nekopics[i] = getImage(getCodeBase(),"images/" + nekosrc[i]);
            }
        }

        public void start()
        {
            if (runner == null)
            {
                runner = new Thread(this);
                runner.start();
            }
        }

        public void stop()
        {
            if (runner != null)
            {
                runner.stop();
                runner = null;
            }
        }

        public void run()
        {
            setBackground(Color.white);

            //run from one side of screen to middle
            nekorun(0 , this.size().width/2);

            //stop and pause
            currentimg = nekopics[2];
            repaint();
            pause(1000);

            //yawn
            currentimg = nekopics[3];
            repaint();
            pause(1000);

            //scratch four times
            nekoscratch(4);

            //sleep for 5 "turns"
            nekosleep(5);

            //wake up and runoff
            currentimg = nekopics[8];
            repaint();
            pause(500);
            nekorun(xpos,this.size().width+10);
        }

        void nekorun(int start , int end)
        {
            for(int i=start;i<end;i+=10)
            {
                this.xpos = i;
                //swap images
                if(currentimg == nekopics[0])
                currentimg = nekopics[1];

                else if(currentimg == nekopics[1])
                currentimg = nekopics[0];
                else currentimg = nekopics[0];

                repaint();
                pause(150);

            }
        }

        void nekoscratch(int numtimes)
        {
            for(int i=numtimes ; i>0 ; i--)
            {
                currentimg = nekopics[4];
                repaint();
                pause(150);

                currentimg = nekopics[5];
                repaint();
                pause(150);

            }
        }

        void nekosleep(int numtimes)
        {
            for(int i=numtimes ; i>0 ; i--)
            {
                currentimg = nekopics[6];
                repaint();
                pause(250);

                currentimg = nekopics[7];
                repaint();
                pause(250);
            }
        }

        void pause(int time)
        {
            try
            {Thread.sleep(time);}
            catch(InterruptedException e){}
        }

        public void paint(Graphics g)
        {
            g.drawImage(currentimg,xpos,ypos,this);
        }


    }

here is the new formatted code.....now it doesn't show any error....but on running it gives no output.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.