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>