简单,改如下:
import java.awt.*;
import java.applet.*;
public class FancyText extends Applet implements Runnable
{
String s=null;
int direct=1;
int Hrad=12;
int Vrad=12;
Thread thread=null;
char words[];
int phase=0;
Image offI;
Graphics offG;
Color colors[];
private Font f;
private FontMetrics fm;
public void init()
{
String param=null;
s=getParameter("word");
setBackground(Color.black);
words=new char[s.length()];
s.getChars(0,s.length(),words,0);
offI=createImage(getSize().width,getSize().height);
offG=offI.getGraphics();
f=new Font("TimeRoman",Font.BOLD,36);
fm=getFontMetrics(f);
offG.setFont(f);
float h;
colors=new Color[s.length()];
for(int i=0;i<s.length();i++)
   {
h=((float)i)/((float)s.length());
colors[i]=new Color(Color.HSBtoRGB(h,1.0f,1.0f));
   }
}
public void start()
{
if(thread==null)
{
thread=new Thread(this);
thread.start();
}
}
public void stop()
{
if(thread!=null)
{
thread.stop();
thread=null;
}
}
public void run()
{
while(thread !=null)
{
try
{
Thread.sleep(200);
}
catch(InterruptedException e)
{
}
repaint();
}
}
public void update(Graphics g)
{
int x,y;
double ang;
offG.setColor(Color.black);
offG.fillRect(0,0,getSize().width,getSize().height);
phase+=direct;
phase%=8;
for(int i=0;i<s.length();i++)
{
ang=((phase-i*direct)%8)/4.0*Math.PI;
x=20*fm.getMaxAdvance()*i+(int)(Math.cos(ang)*Hrad);
y=60+(int)(Math.sin(ang)*Vrad);
offG.setColor(colors[(phase+i)%s.length()]);
offG.drawChars(words,0,2,x,y);//主要是这里,offset设置为0
}
paint(g);
}
public void paint (Graphics g)
{
g.drawImage(offI,0,0,this);
}
}