⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bolang.java

📁 针对越来越多的用户喜欢JAVA
💻 JAVA
字号:
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<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,i,1,x,y);
      }
      paint(g);
   }
  public void paint(Graphics g)
  {
    g.drawImage(offI,0,0,this);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -