简体   繁体   中英

Java Applet : Nested Loops color change

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 http://img291.imageshack.us/img291/2707/15219320.png

what should i do to make it work ?

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM