954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Applet help

So to get practice writing applets, I tried to write one that simply draws a chessboard in a 160 x 160 window. I am pretty sure I got the code right for both the html and java files, and I have the html file in the same directory as my java class file. However, when I attempt to open the html file in IE, it says "Loading Java Applet failed..." at the bottom left of the screen. Anything I can do?

java file code:

package drawchessboard;

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

//this class is written to draw a chessboard in a 160p x 160p applet window

public class Main extends Applet
{
    public void paint(Graphics g)
    {
        int startx=0, starty=0, endx=20, endy=20;
        for(int j=0;j<4;j++)//draws 2 rows
        {
            for(int i=0;i<4;i++) //draws a row starting with a white square
            {
                g.setColor(Color.white);
                g.fillRect(startx, starty, endx, endy); //draw white square 20x20
                startx+=20; //move one 20x20 square over
                endx+=20;
                g.setColor(Color.black);
                g.fillRect(startx, starty, endx, endy); //draw black 20x20 square
                startx+=20; //move one 20x20 square over
                endx+=20;
            }
            starty+=20; //move 20 pixels down
            endy+=20;
            for(int q=0;q<4;q++)
            {
                g.setColor(Color.black);
                g.fillRect(startx, starty, endx, endy); //draw black square 20x20
                startx+=20; //move one 20x20 square over
                endx+=20;
                g.setColor(Color.white);
                g.fillRect(startx, starty, endx, endy); //draw white 20x20 square
                startx+=20; //move one 20x20 square over
                endx+=20;
            }
            starty+=20; //move 20 pixels down
            endy+=20;
        }
    }
}


html file code:

<applet code="Main.class" width=160 height=160>
</applet>
pi_lord12
Light Poster
31 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

Please open the browser's Java console, copy the contents and paste it here.

Remove the package statement or change the

NormR1
Posting Expert
Moderator
6,677 posts since Jun 2010
Reputation Points: 1,138
Solved Threads: 656
 

Thanks, moving it up one level worked...I didn't think about the package

pi_lord12
Light Poster
31 posts since Jun 2010
Reputation Points: 10
Solved Threads: 1
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: