你需要把color_set定义为类的数据成员.
以你的例子,在parseArgs结束时,该变量也就没有了,到setBackground(color_set)时,不知到哪儿去找它,自然就出错了.

解决方案 »

  1.   

    忘了提了,你应该是有一个main入口函数的吧,parseArgs是不能直接从外部调的.
      

  2.   

    //public static Color getColor(String nm)
    //Finds a color in the system properties. 
    //The argument is treated as the name of a system property to be obtained. 
    //The string value of this property is then interpreted as an integer which is then converted to a Color object. 
    //If the specified property is not found or could not be parsed as an integer then null is returned. //需要理解getColor他是从system properties获得值,然后将其转换成相应的integer
    //如果你没有设属性"green",而使用getColor("green"),将只能能得到为null的Color对象
    //依此类推,如
    System.setProperty("myblack",Color.black.getRGB()+"");
    System.setProperty("mygreen",Color.green.getRGB()+"");
    Color color_set=Color.getColor("mygreen");
    System.out.println(color_set);