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

📄 flyfont.java

📁 Java Applet实例编程.rar
💻 JAVA
字号:
import java.awt.*;
import java.applet.*;

public class FlyFont extends Applet implements Runnable{
   
   private Image buffer;
   private Graphics gContext;
   private Font font;
   private String string;
   private Thread thread;
   private int xpos, ypos, font_size;
   
   public void init(){
   
      String param;
      buffer = createImage(getSize().width, getSize().height);   
      gContext = buffer.getGraphics();
      param = getParameter("text");
      if(param == null)
         string = "You Can Input The String That You Want";
      else string = param;
      
      font = new Font("TimesRoman", Font.BOLD, 10);
      
   }
   public void start(){
      if(thread == null){
         thread =  new Thread(this);
         thread.start();
      }
   }
   
   public void update(Graphics g){
      paint(g);
   }
   public void paint(Graphics g){
      gContext.setColor(Color.black);
      gContext.fillRect(0,0,getSize().width, getSize().height);
   
      font = new Font("TimesRoman", Font.BOLD, font_size);
      gContext.setFont(font);
      gContext.setColor(Color.yellow);
      FontMetrics fm = gContext.getFontMetrics(font);
      int font_height = fm.getHeight();
      int w;
      int base_line = getSize().height / 2 + font_height / 2;      
      
      w = fm.stringWidth(string);      
      w = (getSize().width - w) / 2;
      
      gContext.drawString(string, w, base_line-=20);   
      g.drawImage(buffer,0,0, this);
      font_size++;
      

   }
   
   public void run(){
      while(true){
         repaint();
         if(font_size >getSize().height)
            font_size = 0;
         try{
            Thread.sleep(50);
         }catch (InterruptedException e){}
      }      
   }
}

⌨️ 快捷键说明

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