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

📄 rolltext2.java

📁 Java 范例实战 光盘使用说明 ========================== 本光盘的文件结构如下所示: =====================================
💻 JAVA
字号:
import java.applet.Applet;
import java.awt.*;

public class RollText2 extends Applet implements Runnable
{

    String message ;
    Thread show ;
    Color showColor ;
    MediaTracker mtk ;
    FontMetrics fontMet ;
    Graphics offGraphics ;
    Image bgImage, offScreen ;
    int delayTime, clipWidth, strWidth, strHeight, 
    	baseX, baseY, shadowX, shadowY;
    boolean isShow ;
    Font showFont ;

    public RollText2()
    {
        
        mtk = new MediaTracker(this);
        isShow = true;
    
    }

    int getParameter(String s1, int s2) 
    {
    
        String s = getParameter(s1) ;
        return (s != null) ? Integer.parseInt(s) : s2 ;
    
    }

    String getParameter(String s1, String s2) 
    {
    
        String s = getParameter(s1) ;
        return (s != null) ? s : s2 ;
    
    }

    public void init()
    {
    
        message = getParameter("Message", 
        	  "Welcome to my Home Page!!") ;
        String s = getParameter("Style");
        int style = Font.PLAIN ;
        if (s.toUpperCase().indexOf("BOLD") != -1) 
        	style |= Font.BOLD ;
        if (s.toUpperCase().indexOf("ITALIC") != -1) 
        	style |= Font.ITALIC ;
        showFont = new Font(getParameter("Font", "TimesRoman"), 
        		    style, getParameter("size", 16));
        delayTime = getParameter("delayTime", 300);
        clipWidth = getParameter("clipWidth", 15);
        bgImage = getImage(getCodeBase(), 
        	  getParameter("bgImage", "RollText2.jpg"));
        shadowX = getParameter("shadowX", 1);
        shadowY = getParameter("shadowY", 1);
        showColor = Color.red;
        offScreen = createImage(getSize().width, getSize().height);
        offGraphics = offScreen.getGraphics();
        mtk.addImage(bgImage, 0);
    
    }

    public void start()
    {

        if(show == null)
        {

            show = new Thread(this);
            show.start();

        }

    }

    public void stop()
    {

        show = null;

    }

    public void run()
    {

        do
        {

            repaint();
            try
            {

                Thread.sleep(delayTime);

            }
            catch(InterruptedException _ex) { }

        }
        while(true);

    }

    public void update(Graphics g)
    {

        paint(g);

    }

    public void paint(Graphics g)
    {

        if(mtk.statusID(0, true) == MediaTracker.COMPLETE)
        {

            offGraphics.drawImage(bgImage, 0, 0, getSize().width, 
            			getSize().height, this);

        }
        else
        {

            offGraphics.setColor(Color.gray);
            offGraphics.fillRect(0, 0, getSize().width, 
            			getSize().height);

        }
        offGraphics.setFont(showFont);
        if(isShow)
        {

            fontMet = offGraphics.getFontMetrics();
            strWidth = fontMet.stringWidth(message);
            strHeight = fontMet.getAscent();
            baseX = getSize().width;
            baseY = (getSize().height - strHeight) / 2 + strHeight;
            isShow = false;

        }
        if(baseX + strWidth < 0)
        {

            baseX = getSize().width;
            showColor = new Color(
            		(int)Math.floor(Math.random() * 255D), 
            		(int)Math.floor(Math.random() * 255D), 
            		(int)Math.floor(Math.random() * 255D)
            		);

        }
        else
        {

            baseX -= clipWidth;

        }
        offGraphics.setColor(Color.black);
        offGraphics.drawString(message, baseX + shadowX, 
        		       baseY + shadowY);
        offGraphics.setColor(showColor);
        offGraphics.drawString(message, baseX, baseY);
        offGraphics.setColor(Color.black);
        offGraphics.drawRect(0, 0, getSize().width - 1, 
        		     getSize().height - 1);
        offGraphics.drawRect(1, 1, getSize().width - 3, 
        		     getSize().height - 3);
        g.drawImage(offScreen, 0, 0, this);

    }

}

⌨️ 快捷键说明

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