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

📄 colortext.java

📁 java applet 非常全的实例。比较利于初学者进行研究。
💻 JAVA
字号:
import java.applet.*;
import java.awt.*;

public class ColorText extends Applet implements Runnable
{
  private String message = new String("Hello!! Java");
  private Image offI;
  private Graphics offG;
  private Thread thread = null;
  
  
  public void init()
  {
    if(getParameter("Message") != null)
    {
      message = new String(getParameter("Message"));
    }
    offI = createImage(size().width,size().height);
    offG = offI.getGraphics();
    
  }
  
  public void start()
  {
    if(thread == null)
    {
      thread = new Thread(this);
      thread.start();
    }
  }
  
  public void run()
  {
    Color color = Color.black;
    boolean isBlack = true;
    
    while(true)
    {
      if(isBlack)
      {
        for(int i=0; i<255; i+=5)
        {
          try
          {
            thread.sleep(100);
            //System.out.println(i);
            offG.setColor(Color.yellow);
            offG.fillRect(0,0,size().width,size().height);
            color = new Color(i,i,i);
            offG.setColor(color);
            offG.setFont(new Font("TimesRoman",Font.BOLD,20));
            offG.drawString(message,10,(int)(size().height*2/3));
            repaint();
          }
          catch(InterruptedException e){}
        }
        
        isBlack =  false;
      }
      else
      {
        for(int i=255; i>0; i-=5)
        {
          try
          {
            thread.sleep(100);
            //System.out.println(i);
            offG.setColor(Color.yellow);
            offG.fillRect(0,0,size().width,size().height);
            color = new Color(i,i,i);
            offG.setColor(color);
            offG.setFont(new Font("TimesRoman",Font.BOLD,20));
            offG.drawString(message,10,(int)(size().height*2/3));
            //System.out.println(message);
            repaint();
          }
          catch(InterruptedException e){}
        }
        
        isBlack = true;
      }  
    }
  }
  
  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 + -