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

📄 spotlight.java

📁 聚光灯效果.HTML
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;

public class SpotLight extends Applet implements Runnable
{
   private String text;
   private Font font;
   private Color c, spot;
   private int font_size;
   private Thread thread;
   private int textpt = 50;
   private int text_size = 20;
   private int text_width = 0;
   private int font_height,base_line,w;
   
   public void init()
   {
      String fonts, temp;
      text = getParameter("message");
      if(text == null)
         text = "You Can Input Some Message";
      fonts = getParameter("font_size");         
      if(fonts == null)
         font_size = 20;
      else
         font_size = Integer.parseInt(fonts);
         
      font = new Font("TimesRoman", Font.BOLD, font_size);   
      FontMetrics fm = getFontMetrics(font);
      font_height = fm.getHeight();
      base_line = getSize().height / 2 + font_height / 3;
      text_width = fm.stringWidth(text);
      w = fm.stringWidth(text);      
      w = (getSize().width - w) / 2;
      textpt = w;
      c = new Color(255, 0, 0);
      spot = new Color(255, 255, 255);
      setBackground(Color.black);      
   }
   
   public void start()
   {
      if(thread == null)
	  {
         thread = new Thread(this);
         thread.start();
      }
   }
   
   public void stop()
   {
      thread.stop();
      thread = null;
   }
   
   public void run()
   {
      while(true)
	  {
         repaint();
         try { Thread.sleep(50); }
		 catch(InterruptedException e) { }
      }
   }
   
   public void update(Graphics g)
   {
       paint(g);
   }
   
   public void paint(Graphics g)
   {
      g.setFont(font);
      g.setColor(c);
      g.drawString(text, w, base_line);
      g.clipRect(textpt, 0, text_size, getSize().height);
      g.setColor(spot);
      g.drawString(text, w, base_line);
      textpt = (textpt + 1) % (text_width + 100);
   }
}

⌨️ 快捷键说明

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