跪求一段能实现关键字变色的完整程序!
来源:百度知道 编辑:UC知道 时间:2024/05/17 02:35:36
//RainbowText.java
import java.applet.Applet;
import java.awt.*;
public class RainbowText extends Applet
implements Runnable
{
//变量定义
String str = null;
int strlen = 0;
Thread runner = null;
char theChars[] = null;
int charOffsets[] = null;
Color colors[] = null;
int phase = 0;
Image offScreenImage = null;
Graphics offScreenG = null;
Font f = null;
FontMetrics fm = null;
//初始化小程序
public void init()
{
int i = 20;
str = getParameter("text");
if(str == null)
str = "Museum of Java Applets";
f = new Font("TimesRoman", 1, 36);
fm = getFontMetrics(f);
resize(40 + fm.stringWidth(str), 40);
setBackground(Color.black);
strlen = str.length();
theChars = new c