Applet not initialized in applet viewer

591 views Asked by At

I need to write an applet for a computer science course. I need to have five song titles scroll on to the screen from the top and off the right side, one at a time on a loop. I wrote my code and it compiles but when I try to run it in the appletviewer I get a blank window that says applet not initialized. I'm assuming that it's not a problem with the main code and that it's probably something in the start() method. Here's the code:

import java.awt.*;
public class SongTitles extends java.applet.Applet implements Runnable
{
String song[] = {"Watch The Corners","Where Is My Mind","Different World","Seven Nation Army","Nowhere Man"};
int[] y = new int[] {0,0,0,0,0};
int[] x = new int[] {200,200,200,200,200};
boolean[] cycle = new boolean[5];
Thread runner;

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


public void paint (Graphics g)
{
for(int i = 0; i < 5; i++)
{
        g.drawString(song[i], x[i], y[i]);
}
}

public void run()
{
cycle[0] = true;

for(int c = 0; c < 5; c++)
{

        while(cycle[c] = true)
        {
        if (y[c] < 200)
        {
                y[c] += 2;
                repaint();
                try 
                {
                runner.sleep(50);
                }
                catch (InterruptedException e) { }
    }

        if (y[c] == 200 && x[c] < 400)
        {
                x[c] += 2;
                repaint();
                try 
                {
                    runner.sleep(50);
                }
                catch (InterruptedException e) { }
            }

        if (x[c] == 400)
        {
                x[c] = 200;
            y[c] = 0;
                repaint();
        cycle[c] = false;
        cycle[(c + 1)] = true;
                try 
                {
                    runner.sleep(50);
                }
                catch (InterruptedException e) { }
            }

    }

    if(c < 5)
    {
        c++;
    }

    if(c == 5)
    {
        c = 0;
    }
    }
  }
}

And here's the html file to run it:

<html>
<body>
<applet code = "SongTitles.class" width=400 height=400>
</applet>
</body>
</html> 
0

There are 0 answers