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

📄 shadowtext.java

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

public class ShadowText extends Applet implements Runnable
{
  private Image img;
  private Image offI;
  private Graphics offG;
  private Thread thread = null;
  private MediaTracker imageTracker;
  
  private int height,width;
  private String text;
  private int FontSize;
  private Font font;
  private int textcolor, backcolor, shadowcolor;
  
  public void init()
  {    
    width = this.size().width;
    height = this.size().height;
    
    String s = new String(getParameter("Text"));
    
    text = new String("Hello");
    if(s != null)
      text = s;
    FontSize = 30;
    
    s = new String(getParameter("FontSize"));
    if(s != null)
      FontSize = Integer.parseInt(s);
    
    s = getParameter("Fore");
    textcolor = (s==null) ? 0x000000 : Integer.parseInt(s, 16);
    s = getParameter("Back");
    backcolor = (s==null) ? 0x000000 : Integer.parseInt(s, 16);
    s = getParameter("shadow");
    shadowcolor = (s==null) ? 0x000000 : Integer.parseInt(s, 16);
    
    this.setBackground(new Color(backcolor));
    
    img = createImage(width,height);
    Graphics temp = img.getGraphics();
    temp.setColor(new Color(backcolor));
    temp.fillRect(0,0,width,height);
    
    temp.setColor(new Color(shadowcolor));
    
    
      
    font = new Font("TimesRoman",Font.BOLD,FontSize);
    temp.setFont(font);
    temp.drawString(text,10,height*3/4);
    
    temp.setColor(new Color(textcolor));
    temp.drawString(text,10-3,height*3/4 - 3);
    
    imageTracker = new MediaTracker(this);
    imageTracker.addImage(img,0);
    
    try
    {
      imageTracker.waitForID(0);
    }
    catch(InterruptedException e){}
    
    offI = createImage(width,height);
    offG = offI.getGraphics();
    
  }
  
  public void start()
  {
    if(thread == null)
    {
      thread = new Thread(this);
      thread.start();
    }
  }
  
  public void run()
  {
    int x=width;
    while(thread != null)
    {
      try
      {
        offG.drawImage(img,x,0,this);
        repaint();
        thread.sleep(50);
      }
      catch(InterruptedException e){}
      
      x-=3;
      if(x < -width)
      {
        x = width;
      }

    }
  }
  
  public void update(Graphics g)
  {
    paint(g);
  }
  
  public void paint(Graphics g)
  {
    g.drawImage(offI,0,0,this);
  }


}

⌨️ 快捷键说明

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