The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
December 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

Seems easy.. but what have I done wrong here?

Posted by Adam Knutson on December 13, 2001 at 6:43 PM

If this is a repost *Sorry!*
OK, I'm learning java and reading a book on it, by the time I get a reply to this the problem may be solved BUT here goes.. This is just a simple Applet that draws out a 160x160 RED/BLACK checkerboard. However my problem is that I run it on the web page and it just comes up blank(gray). See if you can tell me why this isn't working or what I could do to fix it :) thanks

The source is:

import java.applet.*;

public class CheckerBoard extends Applet {

public void paint(Graphics g) {

int yIn; // The distance from left
int xIn; // The distance from top
int width; // Width of square to draw
int height; // Height of square to draw

yIn = 0;
xIn = 0;
width = 20; //* Static Values
height = 20; //*

while ( yIn <= 160 && xIn <= 160 ) {

if ( xIn == 0 || xIn == 40 || xIn == 80 || xIn ==120 ) {

for ( yIn = 0 ; yIn <= 160 ; yIn += 20 ) {
g.setColor(Color.red); // Start RED
g.fillRect(xIn , yIn , width, height); // Draw RED
yIn += 20; // Move R20
g.setColor(Color.black); // Start BLK
g.fillRect(xIn , yIn, width, height); // Draw BLK
}
} // end if

else {

for ( yIn = 0; yIn <= 160 ; yIn += 20 ) {
g.setColor(Color.black); // Start BLACK
g.fillRect(xIn, yIn, width, height); // Draw BLK
yIn += 20; // Move Rt. 20
g.setColor(Color.red); // Start RED
g.fillRect(xIn, yIn, width, height); // Draw RED
}
} //end else

xIn +=20;

}//end Parent While

} //end paint(Graphics)




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us