Java Applet:嵌套循环颜色更改

时间:2010-05-09 00:14:26

标签: java applet

我喜欢在Java applet中创建一个嵌套循环的表,在这个循环中我应该改变颜色,如图所示。

现在我成功地制作了桌子,但我不能改变颜色,因为每次我尝试论坛时,它都不起作用。

这是我的代码

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

我该怎么做才能让它发挥作用?

1 个答案:

答案 0 :(得分:3)

在您的RGB计算中,您使用x,但x永远不会更改。您需要使用循环控件cr

此外,此行无效:Color C = new Color(0,10 +(x * 2),0);

您只能使用C2设置颜色,因此只需将该行更改为:

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