tags:

views:

129

answers:

1

Hello

I have like a table to make a nested loop in Java applet , during this loop i should change the colors like the picture said.

now i successed to make the table but i cannot change the colors because every time i try a forumla , it doesn't work.

Here is my code

int x = 63;

  for (int r=1; r<=10;r++)
  {

   Color C = new Color(0,10 +(x * 2),0);

   for (int c=0; c<=4; c++)
   {

   Color C2 = new Color(10 + (x * 2) ,0,0);
   g.setColor(C2);
   Font F = new Font("Arial",Font.BOLD, 24);
   g.setFont(F);
   g.drawString("Hello",10 + ( c * 60), r * 25 );

   }
  }

alt text

what should i do to make it work ?

+2  A: 

In your RGB calculations you are using x but x never changes. You need to use your loop controls c and r.

Also, this line doesn't do anything: Color C = new Color(0,10 +(x * 2),0);

You only set the color using C2, so just change that line to look like this:

Color C2 = new Color(10 + (r * 2) ,10 +(c * 2),0);
dbyrne
Thank you so much for this :)
Bader