import java.awt.*;public class MySimpleColor
{
   private Color myColor = null;
   
   public String getMyColor()
   {
     return "" + myColor;
   }
   
   public void setMyColor(Color colour)
   {
     myColor = colour;
   }
   
   public static void main(String [] args)
   {
      MySimpleColor nn = new MySimpleColor();
  nn.setMyColor(Color.red);
  System.out.println("" + nn.getMyColor());
   }
}
the output:java.awt.Color[r=255,g=0,b=0]

解决方案 »

  1.   

    我以前写过一个用字符串保存颜色的,字符串用来表示十六进制的RGB,如"ff0000"表示红色,这样和FireWork里表示的一样。可以用以下的函数得到颜色的int值  public int getRGBValue(String RGB) throws Exception
      {
        String s=RGB.toUpperCase();
        int colorValue=0;
        for(int i=0;i<s.length();i++)
        {
          if(s.charAt(i)<="9".charAt(0) && s.charAt(i)>="0".charAt(0))
            colorValue=s.charAt(i)-"0".charAt(0)+colorValue*16;
          else
            colorValue=s.charAt(i)-"A".charAt(0)+10+colorValue*16;
        }
        return colorValue;
      }要得到对应的Color对象只要象下面这样:
      Color c=new Color(getRGBValue("ff0000"))