CheckerBoard.class is not public or has no constructor

Hi

I have a java applet called CheckerBoard.java

It fails to run and it gives me errors. These errors are pasted as below and the code is pasted below that.

load: CheckerBoard.class is notpublic or has nopublic constructor.

java.lang.IllegalAccessException: Class sun.applet.AppletPanel can not access a member ofclass CheckerBoard with modifiers""

at sun.reflect.Reflection.ensureMemberAccess(Unknown Source)

at java.lang.Class.newInstance0(Unknown Source)

at java.lang.Class.newInstance(Unknown Source)

at sun.applet.AppletPanel.createApplet(Unknown Source)

at sun.plugin.AppletViewer.createApplet(Unknown Source)

at sun.applet.AppletPanel.runLoader(Unknown Source)

at sun.applet.AppletPanel.run(Unknown Source)

at java.lang.Thread.run(Unknown Source)

import java.awt.*;

import java.applet.Applet;

publicclass CheckerBoardextends Applet{

Color redSquare;

Color blackSquare;

CheckerBoard(){

redSquare = Color.RED;

blackSquare = Color.BLACK;

}

publicvoid paint(Graphics g){

int rectWidth = 20;

int rectHeight = 20;

int rowNum;

int colNum;

int x = 0;

int y = 0;

for(rowNum=1;rowNum<9;rowNum++)

{

//Draw a red square

for(colNum=1;colNum<9;colNum++)

{

x = 0;

y = 0;

if((rowNum%2==1 && colNum%2==1) || (rowNum%2==0 && colNum%2==0))

{

g.setColor(redSquare);

g.fillRect(x,y,rectWidth, rectHeight);

x = x+38;

}

elseif(rowNum%2 == 1){

g.setColor(blackSquare);

g.fillRect(x+19,y,rectWidth,rectHeight);

x = x+38;

}

elseif(rowNum%2 == 0){

g.setColor(blackSquare);

g.fillRect(x,y+19, rectWidth,rectHeight);

x=x+38;

}

}//end of inner for loop

}//end of outer for loop

}//end of method 'paint'

}//end of class 'CheckerBoard'

-

I am new to java programming and to Applet. I am not sure how to solve this problem. Many thanks in advance.

[3476 byte] By [ilango171a] at [2007-11-27 11:20:58]
# 1

As the error message states (since the class is declared public), the constructor is not declared public. So, do that:

public CheckerBoard(){

redSquare = Color.RED;

blackSquare = Color.BLACK;

}

ChuckBinga at 2007-7-29 14:45:49 > top of Java-index,Desktop,Core GUI APIs...
# 2

Thanks a lot. Your help is appreciated very much.

ilango171a at 2007-7-29 14:45:49 > top of Java-index,Desktop,Core GUI APIs...