4mod3
asked on
Simple Animation
i have written the following applet to display a red and black chess board :
import java.awt.*;
import java.applet.*;
public class Checker extends Applet {
public void paint(Graphics g) {
int x,y,xint,yint;
xint = 0;
yint = 0;
g.setColor(Color.black);
g.fillRect(0,0,159,159);
g.setColor(Color.red);
for(y = 1; y <= 8; y++) {
for(x = 1; x<=8; x++){
if((((y % 2) == 0) && ((x % 2) == 0)) || (((y % 2) != 0) && ((x % 2) != 0))){
g.fillRect(xint,yint,20,20 );
}
xint += 20;
}
yint +=20;
xint = 0;
}
}
}
is there a way to tweak this so as to produce an animation where the squares alternate colors between red and black ?
import java.awt.*;
import java.applet.*;
public class Checker extends Applet {
public void paint(Graphics g) {
int x,y,xint,yint;
xint = 0;
yint = 0;
g.setColor(Color.black);
g.fillRect(0,0,159,159);
g.setColor(Color.red);
for(y = 1; y <= 8; y++) {
for(x = 1; x<=8; x++){
if((((y % 2) == 0) && ((x % 2) == 0)) || (((y % 2) != 0) && ((x % 2) != 0))){
g.fillRect(xint,yint,20,20
}
xint += 20;
}
yint +=20;
xint = 0;
}
}
}
is there a way to tweak this so as to produce an animation where the squares alternate colors between red and black ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I know how to alternate, just need help animating.