针对越来越多的用户喜欢JAVA

源代码在线查看: bolang.java

软件大小: 702 K
上传用户: tiantianyuehui
关键词: JAVA 用户
下载地址: 免注册下载 普通下载 VIP

相关代码

				import java.awt.*;
				import java.applet.*;
				public class BoLang 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("TimesRoman",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				      {
				         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,i,1,x,y);
				      }
				      paint(g);
				   }
				  public void paint(Graphics g)
				  {
				    g.drawImage(offI,0,0,this);
				  }
				}
							

相关资源