程序:
import java.awt.*;
import java.applet.Applet;
public class col extends Applet
{
Color old; //创建Color类的对象old
String[] Parname ={"red","green","blue"}; //HTML文件提供的三个参数的名称
int[] rgb=new int[3]; //保存三色比例的数组
public void init()
{
for(int i=0;i<Parname.length;i++) //获得HTML文件提供的三色比例
rgb[i]=Integer.parseInt(getParameter(Parname[i]));
}
public void paint(Graphics g)
{
old=g.getColor(); //保存原有的缺省颜色
g.setColor(new Color(rgb[0],rgb[1],rgb[2])); //新建颜色
g.drawString("how do you think about Current color:"+g.getColor().toString(),10,20); //使用新颜色显示
g.setColor(old); //恢复原有颜色
g.drawString("Back to old default color"+g.getColor().toString(),10,40); //使用原有颜色显示
}
}
HTML文件:
<html>
<head><title>col</title></head>
<body>
<hr>
<applet code=col width=500 height=500 >
< PARAM name=red value=200>
< PARAM name=green value=0>
< PARAM name=blue value=0>
</applet><hr>
</body>
</html>