简体   繁体   English

Java Applet:嵌套循环颜色更改

[英]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. 我喜欢用一张表在Java applet中进行嵌套循环,在此循环中,我应该像图片所示更改颜色。

now i successed to make the table but i cannot change the colors because every time i try a forumla , it doesn't work. 现在我成功地制作了桌子,但是我无法更改颜色,因为每次尝试Forumla时,它都不起作用。

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 替代文字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. 在RGB计算中,您使用的是xx永不改变。 You need to use your loop controls c and r . 您需要使用循环控件cr

Also, this line doesn't do anything: Color C = new Color(0,10 +(x * 2),0); 另外,该行不执行任何操作: 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: 您只能使用C2设置颜色,因此只需更改该行即可,如下所示:

Color C2 = new Color(10 + (r * 2) ,10 +(c * 2),0);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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